Skip to content

Commit f11611c

Browse files
thefloweringashdota17
authored andcommitted
json_writer: fix inverted sense in isAnyCharRequiredQuoting (#1120)
This bug is only affects platforms where `char` is unsigned. When char is a signed type, values >= 0x80 are also considered < 0, and hence require escaping due to the < ' ' condition. When char is an unsigned type, values >= 0x80 match none of the conditions and are considered safe to emit without escaping. This shows up as a test failure: * Detail of EscapeSequenceTest/writeEscapeSequence test failure: /build/source/src/test_lib_json/main.cpp(3370): expected == result Expected: '["\"","\\","\b","\f","\n","\r","\t","\u0278","\ud852\udf62"] ' Actual : '["\"","\\","\b","\f","\n","\r","\t","ɸ","𤭢"] '
1 parent 8f7f35c commit f11611c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Diff for: src/lib_json/json_writer.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ static bool isAnyCharRequiredQuoting(char const* s, size_t n) {
178178

179179
char const* const end = s + n;
180180
for (char const* cur = s; cur < end; ++cur) {
181-
if (*cur == '\\' || *cur == '\"' || *cur < ' ' ||
182-
static_cast<unsigned char>(*cur) < 0x80)
181+
if (*cur == '\\' || *cur == '\"' ||
182+
static_cast<unsigned char>(*cur) < ' ' ||
183+
static_cast<unsigned char>(*cur) >= 0x80)
183184
return true;
184185
}
185186
return false;

0 commit comments

Comments
 (0)