Skip to content

Conversation

@csantero
Copy link
Collaborator

@csantero csantero commented Feb 2, 2015

I realized that my code that serializes raw JSON down from the database has no protections to ensure that the data is actually valid JSON. If it's malformed in any way, the formatter will happily send it onto the wire and the client will choke on the response.

I added a check that validates raw json properties before they are serialized. If the property value contains unparseable syntax, like { x }, then the entire object will be sent down as an empty hash {}. If the property value contains unquoted keys, then the keys will be quoted. So { foo: 3 } will be serialized as { "foo": 3 }.

(I originally wanted to have the same behavior if we detect unquoted keys as if the JSON is malformed. But I don't think it's possible to make Json.NET do this - the JToken parser just converts the unquoted keys into quoted ones instead of throwing an exception.)

@csantero
Copy link
Collaborator Author

csantero commented Feb 2, 2015

BTW this will not merge cleanly with #43, so I'll fix and rebase when one is merged.

Conflicts:
	JSONAPI.Tests/Json/JsonApiMediaFormaterTests.cs
@csantero
Copy link
Collaborator Author

csantero commented Feb 3, 2015

Merges cleanly now.

SphtKr added a commit that referenced this pull request Feb 3, 2015
add safeguards against invalid raw json strings
@SphtKr SphtKr merged commit 5bd6d44 into JSONAPIdotNET:master Feb 3, 2015
@csantero csantero deleted the invalid-json branch February 9, 2015 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants