Commits

Anonymous committed 33c70b7

http://code.google.com/p/mochiweb/issues/detail?id=33 fix mochijson:encoder([{input_encoding, utf8}])

Comments (0)

Files changed (1)

src/mochijson.erl

            end,
     [NewC | json_encode_string_utf8_1(Cs)];
 json_encode_string_utf8_1(All=[C | _]) when C >= 16#80, C =< 16#10FFFF ->
-    json_encode_string_unicode(xmerl_ucs:from_utf8(All));
+    [?Q | Rest] = json_encode_string_unicode(xmerl_ucs:from_utf8(All)),
+    Rest;
 json_encode_string_utf8_1([]) ->
     "\"".
 
     end.
 
 test_all() ->
+    test_issue33(),
     test_one(e2j_test_vec(utf8), 1).
 
+test_issue33() ->
+    %% http://code.google.com/p/mochiweb/issues/detail?id=33
+    Js = {struct, [{"key", [194, 163]}]},
+    Encoder = encoder([{input_encoding, utf8}]),
+    "{\"key\":\"\\u00a3\"}" = lists:flatten(Encoder(Js)).
+
 test_one([], _N) ->
     %% io:format("~p tests passed~n", [N-1]),
     ok;