From 7591a663e27d6a0da74750fcfe956d35808174ae Mon Sep 17 00:00:00 2001 From: Bob Ippolito Date: Sat, 4 Apr 2009 21:46:00 +0000 Subject: [PATCH] http://code.google.com/p/mochiweb/issues/detail?id=33 fix mochijson:encoder([{input_encoding, utf8}]) --- src/mochijson.erl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/mochijson.erl b/src/mochijson.erl index 0e887a91..d1ad3fae 100644 --- a/src/mochijson.erl +++ b/src/mochijson.erl @@ -186,7 +186,8 @@ json_encode_string_utf8_1([C | Cs]) when C >= 0, C =< 16#7f -> 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([]) -> "\"". @@ -467,8 +468,15 @@ equiv_list([V1 | L1], [V2 | L2]) -> 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;