mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 08:47:28 +01:00
Let non-strict JSON Pointer syntax allow "~t"
This commit is contained in:
1 parent
42d569f5db
commit
904004e79a
6 files changed
+67
-44
No files matched your search
@@ -176,11 +176,12 @@ static const char* g_usage =
|
||||
"\n"
|
||||
"The -strict-json-pointer-syntax flag restricts the output lines to\n"
|
||||
"exactly RFC 6901, with only two escape sequences: \"~0\" and \"~1\" for\n"
|
||||
"\"~\" and \"/\". Without this flag, this program also lets \"~n\" and\n"
|
||||
"\"~r\" escape the New Line and Carriage Return ASCII control characters,\n"
|
||||
"which can work better with line oriented Unix tools that assume exactly\n"
|
||||
"one value (i.e. one JSON Pointer string) per line. With this flag, it\n"
|
||||
"fails if the input JSON's keys contain \"\\u000A\" or \"\\u000D\".\n"
|
||||
"\"~\" and \"/\". Without this flag, this program also lets \"~n\",\n"
|
||||
"\"~r\" and \"~t\" escape the New Line, Carriage Return and Horizontal\n"
|
||||
"Tab ASCII control characters, which can work better with line oriented\n"
|
||||
"(and tab separated) Unix tools that assume exactly one record (e.g. one\n"
|
||||
"JSON Pointer string) per line. With this flag, it fails if the input\n"
|
||||
"JSON's keys contain \"\\u0009\", \"\\u000A\" or \"\\u000D\".\n"
|
||||
"\n"
|
||||
"----\n"
|
||||
"\n"
|
||||
@@ -328,7 +329,7 @@ struct JsonValue : JsonVariant {
|
||||
bool //
|
||||
escape_needed(const std::string& s) {
|
||||
for (const char& c : s) {
|
||||
if ((c == '~') || (c == '/') || (c == '\n') || (c == '\r')) {
|
||||
if ((c == '~') || (c == '/') || (c == '\n') || (c == '\r') || (c == '\t')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -359,6 +360,12 @@ escape(const std::string& s) {
|
||||
}
|
||||
e += "~r";
|
||||
break;
|
||||
case '\t':
|
||||
if (g_flags.strict_json_pointer_syntax) {
|
||||
return "";
|
||||
}
|
||||
e += "~t";
|
||||
break;
|
||||
default:
|
||||
e += c;
|
||||
break;
|
||||
@@ -395,7 +402,8 @@ print_json_pointers(JsonValue& jvalue, uint32_t depth) {
|
||||
} else {
|
||||
std::string e = escape(kv.first);
|
||||
if (e.empty()) {
|
||||
return "main: unsupported \"\\u000A\" or \"\\u000D\" in object key";
|
||||
return "main: unsupported \"\\u0009\", \"\\u000A\" or \"\\u000D\" in "
|
||||
"object key";
|
||||
}
|
||||
g_dst += e;
|
||||
}
|
||||
@@ -508,7 +516,8 @@ std::string //
|
||||
main1(int argc, char** argv) {
|
||||
TRY(parse_flags(argc, argv));
|
||||
if (!g_flags.strict_json_pointer_syntax) {
|
||||
g_quirks.push_back(WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_R_TILDE_N);
|
||||
g_quirks.push_back(
|
||||
WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T);
|
||||
}
|
||||
|
||||
FILE* in = stdin;
|
||||
|
||||
@@ -241,10 +241,11 @@ static const char* g_usage =
|
||||
"\n"
|
||||
"The -strict-json-pointer-syntax flag restricts the -query=STR string to\n"
|
||||
"exactly RFC 6901, with only two escape sequences: \"~0\" and \"~1\" for\n"
|
||||
"\"~\" and \"/\". Without this flag, this program also lets \"~n\" and\n"
|
||||
"\"~r\" escape the New Line and Carriage Return ASCII control characters,\n"
|
||||
"which can work better with line oriented Unix tools that assume exactly\n"
|
||||
"one value (i.e. one JSON Pointer string) per line.\n"
|
||||
"\"~\" and \"/\". Without this flag, this program also lets \"~n\",\n"
|
||||
"\"~r\" and \"~t\" escape the New Line, Carriage Return and Horizontal\n"
|
||||
"Tab ASCII control characters, which can work better with line oriented\n"
|
||||
"(and tab separated) Unix tools that assume exactly one record (e.g. one\n"
|
||||
"JSON Pointer string) per line.\n"
|
||||
"\n"
|
||||
"----\n"
|
||||
"\n"
|
||||
@@ -660,6 +661,10 @@ class Query {
|
||||
if (*ptr != '\r') {
|
||||
break;
|
||||
}
|
||||
} else if (*j == 't') {
|
||||
if (*ptr != '\t') {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@@ -693,7 +698,7 @@ class Query {
|
||||
// Pointer. In particular, it must be valid UTF-8, and either be empty or
|
||||
// start with a '/'. Any '~' within must immediately be followed by either
|
||||
// '0' or '1'. If strict_json_pointer_syntax is false, a '~' may also be
|
||||
// followed by either 'n' or 'r'.
|
||||
// followed by either 'n', 'r' or 't'.
|
||||
static bool validate(char* query_c_string,
|
||||
size_t length,
|
||||
bool strict_json_pointer_syntax) {
|
||||
@@ -719,6 +724,7 @@ class Query {
|
||||
break;
|
||||
case 'n':
|
||||
case 'r':
|
||||
case 't':
|
||||
if (strict_json_pointer_syntax) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user