make folly::toJson retain non-ascii chars if encode_non_ascii is disabled
authorHari Manikarnika <shreehari@fb.com>
Fri, 26 Oct 2012 23:05:01 +0000 (16:05 -0700)
committerJordan DeLong <jdelong@fb.com>
Sun, 16 Dec 2012 22:40:51 +0000 (14:40 -0800)
commite18efdc462d800421fc1e8af0ed37a4b438dcaf9
treef6eaf3f3aa04a4d7020fd702de88d746109c81a2
parent6e230a3f70594bf25aab067b97beee1c3cc55c14
make folly::toJson retain non-ascii chars if encode_non_ascii is disabled

Summary:
folly::toJson as demonstrated by the test cases was wrongly encoding utf8 strings.
specifically, a utf8 char made up of x bytes was encodeded into x unicode chars.

for example, the char:
\u2665
which is made of 3 bytes:
\xe2\x99\xa5
was encoded correctly when using encode_non_ascii = true:
"\u2665"
but when encode_non_ascii = false, the json value was wrongly set as:
"\u00e2\u0099\u00a5"

because we use an signed char that wrongly detects non-readable chars with
ascii value > 127 as control chars with ascii value < 32 (\t, \n, etc.)

Test Plan: run the test

Reviewed By: delong.j@fb.com

FB internal diff: D612782
folly/json.cpp
folly/test/JsonTest.cpp