From 9dd596b95b05e1cb591d7f4f5eb6c205efd3209b Mon Sep 17 00:00:00 2001 From: Bob Ippolito Date: Thu, 26 Apr 2012 12:41:20 -0700 Subject: [PATCH 1/2] failing test case for \/ --- .gitignore | 1 + priv/test_cases/escapes.json | 1 + priv/test_cases/escapes.test | 5 +++++ 3 files changed, 7 insertions(+) create mode 100644 priv/test_cases/escapes.json create mode 100644 priv/test_cases/escapes.test diff --git a/.gitignore b/.gitignore index 678b670..ba3a5b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ ebin/ deps/ *.orig +/.eunit diff --git a/priv/test_cases/escapes.json b/priv/test_cases/escapes.json new file mode 100644 index 0000000..7c16923 --- /dev/null +++ b/priv/test_cases/escapes.json @@ -0,0 +1 @@ +[ "\"\\\/\b\f\n\r\t\u0020" ] diff --git a/priv/test_cases/escapes.test b/priv/test_cases/escapes.test new file mode 100644 index 0000000..ac1ea14 --- /dev/null +++ b/priv/test_cases/escapes.test @@ -0,0 +1,5 @@ +{name, "escapes"}. +{jsx, [start_array, + {string,<<"\"\\/\b\f\n\r\t ">>}, + end_array,end_json]}. +{json, "escapes.json"}. From 6ff1471550afe5db3ed4b0941c451a83913f61b6 Mon Sep 17 00:00:00 2001 From: Bob Ippolito Date: Thu, 26 Apr 2012 13:04:17 -0700 Subject: [PATCH 2/2] handle escaped solidus correctly per JSON spec --- README.markdown | 4 ++-- src/jsx_decoder.erl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.markdown b/README.markdown index 89f59ea..2c39ba0 100644 --- a/README.markdown +++ b/README.markdown @@ -109,7 +109,7 @@ json text input and json strings SHOULD be utf8 encoded binaries, appropriately #### `escaped_forward_slashes` #### -json strings are escaped according to the json spec. this means forward slashes are never escaped. unfortunately, a microsoft implementation of json uses escaped forward slashes in json formatted date strings. without this option it is impossible to get date strings that some microsoft tools understand +json strings are escaped according to the json spec. this means forward slashes (solidus) are optionally escaped. this option is only relevant for encoding, you may want to use this if you are embedding JSON directly into a HTML or XML document. See: [html4-non-html-data] #### `single_quoted_strings` #### @@ -343,4 +343,4 @@ jsx wouldn't be what it is without the contributions of paul davis, lloyd hilaie [MIT]: http://www.opensource.org/licenses/mit-license.html [rebar]: https://github.com/basho/rebar [meck]: https://github.com/eproxus/meck -[rfc4627]: http://tools.ietf.org/html/rfc4627 \ No newline at end of file +[rfc4627]: http://tools.ietf.org/html/rfc4627[html4-non-html-data]: http://www.w3.org/TR/html4/appendix/notes.html#h-B.3.2 diff --git a/src/jsx_decoder.erl b/src/jsx_decoder.erl index 06239ec..5e72394 100644 --- a/src/jsx_decoder.erl +++ b/src/jsx_decoder.erl @@ -600,7 +600,7 @@ escape(<<$t, Rest/binary>>, Handler, [Acc|Stack], Opts) -> string(Rest, Handler, [?acc_seq(Acc, maybe_replace($\t, Opts))|Stack], Opts); escape(<>, Handler, [Acc|Stack], Opts) -> string(Rest, Handler, [?acc_seq(Acc, maybe_replace($\\, Opts))|Stack], Opts); -escape(<>, Handler, [Acc|Stack], Opts=#opts{escaped_forward_slashes=true}) -> +escape(<>, Handler, [Acc|Stack], Opts) -> string(Rest, Handler, [?acc_seq(Acc, maybe_replace($/, Opts))|Stack], Opts); escape(<>, Handler, [Acc|Stack], Opts) -> string(Rest, Handler, [?acc_seq(Acc, maybe_replace($\", Opts))|Stack], Opts);