Skip to content

Commit ee4ded1

Browse files
committed
Unicode escapes *are* required for JSON control characters
1 parent 508df69 commit ee4ded1

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

Sming/Core/Data/Format/Formatter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ unsigned escapeControls(String& value, Options options)
5858
if(escapeChar(c, options)) {
5959
extra += 1; // "\"
6060
} else if(options[Option::unicode]) {
61-
if(uint8_t(c) < 0x20 || (c & 0x80)) {
61+
if(uint8_t(c) < 0x20) {
6262
extra += 5; // "\uNNNN"
6363
}
6464
} else if(uint8_t(c) < 0x20) {
@@ -86,7 +86,7 @@ unsigned escapeControls(String& value, Options options)
8686
*out++ = '\\';
8787
c = esc;
8888
} else if(options[Option::unicode]) {
89-
if(uint8_t(c) < 0x20 || (c & 0x80)) {
89+
if(uint8_t(c) < 0x20) {
9090
*out++ = '\\';
9191
*out++ = 'u';
9292
*out++ = '0';

Sming/Core/Data/Format/Json.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Json json;
2727
*/
2828
void Json::escape(String& value) const
2929
{
30-
escapeControls(value, Option::doublequote | Option::backslash);
30+
escapeControls(value, Option::unicode | Option::doublequote | Option::backslash);
3131
}
3232

3333
void Json::quote(String& value) const

tests/HostTests/modules/Formatter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class FormatterTest : public TestGroup
1717
TEST_CASE("JSON")
1818
{
1919
DEFINE_FSTR_LOCAL(text1b, "A JSON\\ntest string\\twith escapes\\u0012\\u0000\\n"
20-
"Worth \\\"maybe\\\" \\u00a3 0.53. Yen \\u00a5 5bn.")
20+
"Worth \\\"maybe\\\" \xa3 0.53. Yen \xa5 5bn.")
2121

2222
Serial << text1 << endl;
2323
String s(text1);

0 commit comments

Comments
 (0)