File tree Expand file tree Collapse file tree 4 files changed +23
-2
lines changed
Expand file tree Collapse file tree 4 files changed +23
-2
lines changed Original file line number Diff line number Diff line change 1010* Improve message when user forgets third arg of ` serializeJson() ` et al.
1111* Set ` ARDUINOJSON_USE_DOUBLE ` to ` 0 ` by default on 8-bit architectures
1212* Deprecate ` containsKey() ` in favor of ` doc["key"].is<T>() `
13+ * Add support for escape sequence ` \' ` (issue #2124 )
1314
1415| Architecture | before | after |
1516| --------------| ----------| ----------|
Original file line number Diff line number Diff line change @@ -83,6 +83,22 @@ TEST_CASE("Truncated JSON string") {
8383 }
8484}
8585
86+ TEST_CASE (" Escape single quote in single quoted string" ) {
87+ JsonDocument doc;
88+
89+ DeserializationError err = deserializeJson (doc, " 'ab\\\' cd'" );
90+ REQUIRE (err == DeserializationError::Ok);
91+ CHECK (doc.as <std::string>() == " ab\' cd" );
92+ }
93+
94+ TEST_CASE (" Escape double quote in double quoted string" ) {
95+ JsonDocument doc;
96+
97+ DeserializationError err = deserializeJson (doc, " 'ab\\\" cd'" );
98+ REQUIRE (err == DeserializationError::Ok);
99+ CHECK (doc.as <std::string>() == " ab\" cd" );
100+ }
101+
86102TEST_CASE (" Invalid JSON string" ) {
87103 const char * testCases[] = {" '\\ u'" , " '\\ u000g'" , " '\\ u000'" ,
88104 " '\\ u000G'" , " '\\ u000/'" , " '\\ x1234'" };
Original file line number Diff line number Diff line change @@ -46,6 +46,10 @@ TEST_CASE("serializeJson(JsonVariant)") {
4646 check (" fifty/fifty" _s, " \" fifty/fifty\" " );
4747 }
4848
49+ SECTION (" Don't escape single quote" ) {
50+ check (" hello'world" _s, " \" hello'world\" " );
51+ }
52+
4953 SECTION (" Escape backspace" ) {
5054 check (" hello\b world" _s, " \" hello\\ bworld\" " );
5155 }
Original file line number Diff line number Diff line change @@ -32,8 +32,8 @@ class EscapeSequence {
3232 }
3333
3434 private:
35- static const char * escapeTable (bool excludeSolidus ) {
36- return &" //\"\"\\\\ b\b f\f n\n r\r t\t " [excludeSolidus ? 2 : 0 ];
35+ static const char * escapeTable (bool isSerializing ) {
36+ return &" //'' \"\"\\\\ b\b f\f n\n r\r t\t " [isSerializing ? 4 : 0 ];
3737 }
3838};
3939
You can’t perform that action at this time.
0 commit comments