Changeset 225699 in webkit


Ignore:
Timestamp:
Dec 8, 2017 2:05:07 PM (6 years ago)
Author:
commit-queue@webkit.org
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 <david_quesada@apple.com> 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 JavaScriptCore to WTF's JSON
parsing. Update the unit test accordingly.

  • TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp:

(TEST_F):

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/wtf/JSONValues.cpp

    r225231 r225699  
    537537    const UChar* tokenEnd;
    538538    auto result = buildValue(start, end, &tokenEnd, 0);
    539     if (!result || tokenEnd != end)
    540         return false;
     539    if (!result)
     540        return false;
     541
     542    for (const UChar* valueEnd = tokenEnd; valueEnd < end; ++valueEnd) {
     543        if (!isSpaceOrNewline(*valueEnd))
     544            return false;
     545    }
    541546
    542547    output = WTFMove(result);
  • trunk/Source/WebCore/ChangeLog

    r225696 r225699  
     12017-12-08  David Quesada  <david_quesada@apple.com>
     2
     3        ApplicationManifestParser should strip whitespace from the raw input
     4        https://bugs.webkit.org/show_bug.cgi?id=180539
     5        rdar://problem/35915075
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        * Modules/applicationmanifest/ApplicationManifestParser.cpp:
     10        (WebCore::ApplicationManifestParser::parseManifest):
     11
    1122017-12-08  Eric Carlson  <eric.carlson@apple.com>
    213
  • trunk/Tools/ChangeLog

    r225698 r225699  
     12017-12-08  David Quesada  <david_quesada@apple.com>
     2
     3        ApplicationManifestParser should strip whitespace from the raw input
     4        https://bugs.webkit.org/show_bug.cgi?id=180539
     5        rdar://problem/35915075
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        Added an API test for parsing manifests with surrounding whitespace.
     10
     11        Also drive-by fix ApplicationManifestParserTest.Display. Earlier versions of the
     12        manifest spec explicitly stated that the "display" value should be treated as if
     13        it were run through String.prototype.trim(), which allowed for the really weird
     14        edge case of an array containing one string. This behavior was lost when I changed
     15        ApplicationManifestParser's JSON parsing from using JavaScriptCore to WTF's JSON
     16        parsing. Update the unit test accordingly.
     17
     18        * TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp:
     19        (TEST_F):
     20
    1212017-12-08  Konstantin Tokarev  <annulen@yandex.ru>
    222
  • trunk/Tools/TestWebKitAPI/Tests/WTF/JSONValue.cpp

    r225425 r225699  
    636636        EXPECT_FALSE(JSON::Value::parseJSON("[{\"foo\":{\"baz\":false}]", value));
    637637    }
     638
     639    {
     640        RefPtr<JSON::Value> value;
     641        EXPECT_TRUE(JSON::Value::parseJSON(" \"foo\" \n", value));
     642        String stringValue;
     643        EXPECT_TRUE(value->asString(stringValue));
     644        EXPECT_EQ("foo", stringValue);
     645    }
     646
     647    {
     648        RefPtr<JSON::Value> value;
     649        EXPECT_TRUE(JSON::Value::parseJSON(" 1", value));
     650        EXPECT_TRUE(JSON::Value::parseJSON("\t1", value));
     651        EXPECT_TRUE(JSON::Value::parseJSON("\n1", value));
     652        EXPECT_TRUE(JSON::Value::parseJSON("1 ", value));
     653        EXPECT_TRUE(JSON::Value::parseJSON("1\t", value));
     654        EXPECT_TRUE(JSON::Value::parseJSON("1\n", value));
     655        EXPECT_TRUE(JSON::Value::parseJSON(" 1 ", value));
     656        EXPECT_TRUE(JSON::Value::parseJSON(" {} ", value));
     657        EXPECT_TRUE(JSON::Value::parseJSON(" [] ", value));
     658
     659        EXPECT_FALSE(JSON::Value::parseJSON("1 1", value));
     660        EXPECT_FALSE(JSON::Value::parseJSON("{} {}", value));
     661        EXPECT_FALSE(JSON::Value::parseJSON("[] []", value));
     662    }
    638663}
    639664
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp

    r225639 r225699  
    207207    testDisplay("\"minimal-ui\"", ApplicationManifest::Display::MinimalUI);
    208208    testDisplay("\"fullscreen\"", ApplicationManifest::Display::Fullscreen);
    209 
    210     testDisplay("[\"\\tMINIMAL-ui\\t\"]", ApplicationManifest::Display::MinimalUI);
     209    testDisplay("\"\t\nMINIMAL-UI \"", ApplicationManifest::Display::MinimalUI);
    211210}
    212211
     
    287286}
    288287
     288TEST_F(ApplicationManifestParserTest, Whitespace)
     289{
     290    auto manifest = parseString(ASCIILiteral("  { \"name\": \"PASS\" }\n"));
     291
     292    EXPECT_STREQ("PASS", manifest.name.utf8().data());
     293}
     294
    289295#endif
Note: See TracChangeset for help on using the changeset viewer.