Skip to content

Commit 1e2fac3

Browse files
Mizuchimeta-codesync[bot]
authored andcommitted
Treat '\f' and '\v' as whitespace
Summary: Recognize form feed (`\f`) and vertical tab (`\v`) as whitespace characters when `allow_json5_experimental` is enabled. Reviewed By: ilvokhin Differential Revision: D93462431 fbshipit-source-id: 11b515073b08007f9771b66b4274017ce86a0a1f
1 parent 38671c8 commit 1e2fac3

3 files changed

Lines changed: 40 additions & 2 deletions

File tree

third-party/folly/src/folly/json/json.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,11 @@ struct Input {
431431
index++;
432432
continue;
433433
}
434+
if (opts_.allow_json5_experimental &&
435+
(range_[index] == '\f' || range_[index] == '\v')) {
436+
index++;
437+
continue;
438+
}
434439
}
435440
break;
436441
}

third-party/folly/src/folly/json/test/Json5Test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ constexpr auto kPassedTests = {
8484
"src/misc/npm-package.json",
8585
"src/misc/npm-package.json5",
8686
"src/misc/readme-example.json5",
87+
"src/misc/valid-whitespace.json5",
8788
// Objects - single-quoted keys
8889
"src/objects/single-quoted-key.json5",
8990
// New lines
@@ -169,8 +170,6 @@ constexpr auto kPassedTests = {
169170
};
170171

171172
constexpr auto kFailedTests = {
172-
// Misc
173-
"src/misc/valid-whitespace.json5",
174173
// Numbers
175174
"src/numbers/negative-noctal.js",
176175
"src/numbers/negative-octal.txt",

third-party/folly/src/folly/json/test/JsonTest.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,3 +1358,37 @@ TEST(Json5, MinMaxHexNumbers) {
13581358
EXPECT_EQ(parseJson(maxDoublePlusOne, numberAsString), maxDoublePlusOne);
13591359
EXPECT_EQ(parseJson(minDoubleMinusOne, numberAsString), minDoubleMinusOne);
13601360
}
1361+
1362+
TEST(Json5, FormFeedWhitespace) {
1363+
// Form feed (\f = 0x0c) as whitespace
1364+
EXPECT_EQ(fromJson5("{\f\"a\":\ftrue\f}")["a"], true);
1365+
EXPECT_EQ(fromJson5("[\f1\f,\f2\f]")[0], 1);
1366+
EXPECT_EQ(fromJson5("\f42\f"), 42);
1367+
1368+
// Vertical tab (\v = 0x0b) as whitespace
1369+
EXPECT_EQ(fromJson5("{\v\"a\":\vtrue\v}")["a"], true);
1370+
EXPECT_EQ(fromJson5("\v42\v"), 42);
1371+
1372+
// Mixed with other whitespace
1373+
EXPECT_EQ(fromJson5("{ \f\v\t\n\"a\" : true }")["a"], true);
1374+
1375+
// Vertical tab and form feed between array elements
1376+
auto arr = fromJson5("[\v1\v,\f2\f,\v3\v]");
1377+
EXPECT_EQ(arr[0], 1);
1378+
EXPECT_EQ(arr[1], 2);
1379+
EXPECT_EQ(arr[2], 3);
1380+
1381+
// Form feed between object key-value pairs
1382+
auto obj = fromJson5("{\"a\":\f1\f,\f\"b\":\f2}");
1383+
EXPECT_EQ(obj["a"], 1);
1384+
EXPECT_EQ(obj["b"], 2);
1385+
1386+
// Vertical tab before/after string values
1387+
EXPECT_EQ(fromJson5("\v\"hello\"\v"), "hello");
1388+
1389+
// Form feed only (no value) should fail
1390+
EXPECT_THROW(fromJson5("\f"), std::exception);
1391+
1392+
// Without json5 flag, form feed should fail
1393+
EXPECT_THROW(parseJson("\f42"), std::exception);
1394+
}

0 commit comments

Comments
 (0)