- Revision
- 225699
- Author
- [email protected]
- Date
- 2017-12-08 14:05:07 -0800 (Fri, 08 Dec 2017)
Log Message
ApplicationManifestParser should strip whitespace from the raw input
https://bugs.webkit.org/show_bug.cgi?id=180539
rdar://problem/35915075
Patch by David Quesada <[email protected]> on 2017-12-08
Reviewed by Joseph Pecoraro.
Source/WebCore:
* Modules/applicationmanifest/ApplicationManifestParser.cpp:
(WebCore::ApplicationManifestParser::parseManifest):
Tools:
Added an API test for parsing manifests with surrounding whitespace.
Also drive-by fix ApplicationManifestParserTest.Display. Earlier versions of the
manifest spec explicitly stated that the "display" value should be treated as if
it were run through String.prototype.trim(), which allowed for the really weird
edge case of an array containing one string. This behavior was lost when I changed
ApplicationManifestParser's JSON parsing from using _javascript_Core to WTF's JSON
parsing. Update the unit test accordingly.
* TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp:
(TEST_F):
Modified Paths
Diff
Modified: trunk/Source/WTF/wtf/JSONValues.cpp (225698 => 225699)
--- trunk/Source/WTF/wtf/JSONValues.cpp 2017-12-08 21:56:09 UTC (rev 225698)
+++ trunk/Source/WTF/wtf/JSONValues.cpp 2017-12-08 22:05:07 UTC (rev 225699)
@@ -536,9 +536,14 @@
const UChar* end = start + jsonInput.length();
const UChar* tokenEnd;
auto result = buildValue(start, end, &tokenEnd, 0);
- if (!result || tokenEnd != end)
+ if (!result)
return false;
+ for (const UChar* valueEnd = tokenEnd; valueEnd < end; ++valueEnd) {
+ if (!isSpaceOrNewline(*valueEnd))
+ return false;
+ }
+
output = WTFMove(result);
return true;
}
Modified: trunk/Source/WebCore/ChangeLog (225698 => 225699)
--- trunk/Source/WebCore/ChangeLog 2017-12-08 21:56:09 UTC (rev 225698)
+++ trunk/Source/WebCore/ChangeLog 2017-12-08 22:05:07 UTC (rev 225699)
@@ -1,3 +1,14 @@
+2017-12-08 David Quesada <[email protected]>
+
+ ApplicationManifestParser should strip whitespace from the raw input
+ https://bugs.webkit.org/show_bug.cgi?id=180539
+ rdar://problem/35915075
+
+ Reviewed by Joseph Pecoraro.
+
+ * Modules/applicationmanifest/ApplicationManifestParser.cpp:
+ (WebCore::ApplicationManifestParser::parseManifest):
+
2017-12-08 Eric Carlson <[email protected]>
Move Logger from PAL to WTF so it can be used outside of WebCore
Modified: trunk/Tools/ChangeLog (225698 => 225699)
--- trunk/Tools/ChangeLog 2017-12-08 21:56:09 UTC (rev 225698)
+++ trunk/Tools/ChangeLog 2017-12-08 22:05:07 UTC (rev 225699)
@@ -1,3 +1,23 @@
+2017-12-08 David Quesada <[email protected]>
+
+ ApplicationManifestParser should strip whitespace from the raw input
+ https://bugs.webkit.org/show_bug.cgi?id=180539
+ rdar://problem/35915075
+
+ Reviewed by Joseph Pecoraro.
+
+ Added an API test for parsing manifests with surrounding whitespace.
+
+ Also drive-by fix ApplicationManifestParserTest.Display. Earlier versions of the
+ manifest spec explicitly stated that the "display" value should be treated as if
+ it were run through String.prototype.trim(), which allowed for the really weird
+ edge case of an array containing one string. This behavior was lost when I changed
+ ApplicationManifestParser's JSON parsing from using _javascript_Core to WTF's JSON
+ parsing. Update the unit test accordingly.
+
+ * TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp:
+ (TEST_F):
+
2017-12-08 Konstantin Tokarev <[email protected]>
[python] Replace print operator with print() function for python3 compatibility
Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/JSONValue.cpp (225698 => 225699)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/JSONValue.cpp 2017-12-08 21:56:09 UTC (rev 225698)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/JSONValue.cpp 2017-12-08 22:05:07 UTC (rev 225699)
@@ -635,6 +635,31 @@
EXPECT_FALSE(JSON::Value::parseJSON("[{\"foo\":\"bar\"},{\"baz\":false},]", value));
EXPECT_FALSE(JSON::Value::parseJSON("[{\"foo\":{\"baz\":false}]", value));
}
+
+ {
+ RefPtr<JSON::Value> value;
+ EXPECT_TRUE(JSON::Value::parseJSON(" \"foo\" \n", value));
+ String stringValue;
+ EXPECT_TRUE(value->asString(stringValue));
+ EXPECT_EQ("foo", stringValue);
+ }
+
+ {
+ RefPtr<JSON::Value> value;
+ EXPECT_TRUE(JSON::Value::parseJSON(" 1", value));
+ EXPECT_TRUE(JSON::Value::parseJSON("\t1", value));
+ EXPECT_TRUE(JSON::Value::parseJSON("\n1", value));
+ EXPECT_TRUE(JSON::Value::parseJSON("1 ", value));
+ EXPECT_TRUE(JSON::Value::parseJSON("1\t", value));
+ EXPECT_TRUE(JSON::Value::parseJSON("1\n", value));
+ EXPECT_TRUE(JSON::Value::parseJSON(" 1 ", value));
+ EXPECT_TRUE(JSON::Value::parseJSON(" {} ", value));
+ EXPECT_TRUE(JSON::Value::parseJSON(" [] ", value));
+
+ EXPECT_FALSE(JSON::Value::parseJSON("1 1", value));
+ EXPECT_FALSE(JSON::Value::parseJSON("{} {}", value));
+ EXPECT_FALSE(JSON::Value::parseJSON("[] []", value));
+ }
}
TEST(JSONValue, MemoryCost)
Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp (225698 => 225699)
--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp 2017-12-08 21:56:09 UTC (rev 225698)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp 2017-12-08 22:05:07 UTC (rev 225699)
@@ -206,8 +206,7 @@
testDisplay("\"standalone\"", ApplicationManifest::Display::Standalone);
testDisplay("\"minimal-ui\"", ApplicationManifest::Display::MinimalUI);
testDisplay("\"fullscreen\"", ApplicationManifest::Display::Fullscreen);
-
- testDisplay("[\"\\tMINIMAL-ui\\t\"]", ApplicationManifest::Display::MinimalUI);
+ testDisplay("\"\t\nMINIMAL-UI \"", ApplicationManifest::Display::MinimalUI);
}
TEST_F(ApplicationManifestParserTest, Name)
@@ -286,4 +285,11 @@
testScope("\"https://example.com/other\"", String("https://example.com/other/start-url"), "https://example.com/other");
}
+TEST_F(ApplicationManifestParserTest, Whitespace)
+{
+ auto manifest = parseString(ASCIILiteral(" { \"name\": \"PASS\" }\n"));
+
+ EXPECT_STREQ("PASS", manifest.name.utf8().data());
+}
+
#endif