-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src,test: fix JSON escaping in node-report
Previously only simple escape sequences were handled (i.e. \n, \t, r etc.). This commit adds escaping of other control symbols in the range of 0x00 to 0x20. Also, this replaces multiple find+replace calls with a single pass replacer. PR-URL: #25626 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Richard Lau <[email protected]>
- Loading branch information
1 parent
f8d52c2
commit 80441c8
Showing
3 changed files
with
60 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "node_report.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
TEST(ReportUtilTest, EscapeJsonChars) { | ||
using report::EscapeJsonChars; | ||
EXPECT_EQ("abc", EscapeJsonChars("abc")); | ||
EXPECT_EQ("abc\\n", EscapeJsonChars("abc\n")); | ||
EXPECT_EQ("abc\\nabc", EscapeJsonChars("abc\nabc")); | ||
EXPECT_EQ("abc\\\\", EscapeJsonChars("abc\\")); | ||
EXPECT_EQ("abc\\\"", EscapeJsonChars("abc\"")); | ||
|
||
const std::string expected[0x20] = { | ||
"\\u0000", "\\u0001", "\\u0002", "\\u0003", "\\u0004", "\\u0005", | ||
"\\u0006", "\\u0007", "\\b", "\\t", "\\n", "\\v", "\\f", "\\r", | ||
"\\u000e", "\\u000f", "\\u0010", "\\u0011", "\\u0012", "\\u0013", | ||
"\\u0014", "\\u0015", "\\u0016", "\\u0017", "\\u0018", "\\u0019", | ||
"\\u001a", "\\u001b", "\\u001c", "\\u001d", "\\u001e", "\\u001f" | ||
}; | ||
for (int i = 0; i < 0x20; ++i) { | ||
char symbols[1] = { static_cast<char>(i) }; | ||
std::string input(symbols, 1); | ||
EXPECT_EQ(expected[i], EscapeJsonChars(input)); | ||
EXPECT_EQ("a" + expected[i], EscapeJsonChars("a" + input)); | ||
} | ||
} |