Changeset 205400 in webkit


Ignore:
Timestamp:
Sep 3, 2016 7:09:58 AM (8 years ago)
Author:
Chris Dumez
Message:

Align meta element http-equiv="refresh" parsing with the HTML specification
https://bugs.webkit.org/show_bug.cgi?id=161543

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

Import corresponding test from W3C.

  • web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/parsing-expected.txt: Added.
  • web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/parsing.html: Added.
  • web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/;url=foo: Added.
  • web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/dir.headers: Added.
  • web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/foo: Added.
  • web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/foo'bar: Added.
  • web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/refresh.sub.html: Added.
  • web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/ufoo: Added.
  • web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/urfoo: Added.
  • web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/url foo: Added.
  • web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/urlfoo: Added.
  • web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/x;url=foo: Added.

Source/WebCore:

Align meta element http-equiv="refresh" parsing with the HTML specification:

Tests: imported/w3c/web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/parsing.html

  • dom/Document.cpp:

(WebCore::Document::processHttpEquiv):

  • html/parser/HTMLParserIdioms.cpp:

(WebCore::parseHTTPRefreshInternal):
(WebCore::parseMetaHTTPEquivRefresh):

  • html/parser/HTMLParserIdioms.h:
  • loader/FrameLoader.cpp:

(WebCore::FrameLoader::receivedFirstData):

  • platform/network/HTTPParsers.cpp:

(WebCore::skipWhiteSpace):
(WebCore::skipEquals):
(WebCore::parseHTTPRefresh):
(WebCore::parseXSSProtectionHeader):
(WebCore::skipValue): Deleted.

  • platform/network/HTTPParsers.h:

LayoutTests:

Update layout test to only use HTML spaces in http-equiv="refresh"
content value.

  • http/tests/misc/refresh-meta-with-newline.html:
Location:
trunk
Files:
15 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r205399 r205400  
     12016-09-03  Chris Dumez  <cdumez@apple.com>
     2
     3        Align meta element http-equiv="refresh" parsing with the HTML specification
     4        https://bugs.webkit.org/show_bug.cgi?id=161543
     5
     6        Reviewed by Darin Adler.
     7
     8        Update layout test to only use HTML spaces in http-equiv="refresh"
     9        content value.
     10
     11        * http/tests/misc/refresh-meta-with-newline.html:
     12
    1132016-09-03  Youenn Fablet  <youenn@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r205399 r205400  
     12016-09-03  Chris Dumez  <cdumez@apple.com>
     2
     3        Align meta element http-equiv="refresh" parsing with the HTML specification
     4        https://bugs.webkit.org/show_bug.cgi?id=161543
     5
     6        Reviewed by Darin Adler.
     7
     8        Import corresponding test from W3C.
     9
     10        * web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/parsing-expected.txt: Added.
     11        * web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/parsing.html: Added.
     12        * web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/;url=foo: Added.
     13        * web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/__dir__.headers: Added.
     14        * web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/foo: Added.
     15        * web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/foo'bar: Added.
     16        * web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/refresh.sub.html: Added.
     17        * web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/ufoo: Added.
     18        * web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/urfoo: Added.
     19        * web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/url foo: Added.
     20        * web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/urlfoo: Added.
     21        * web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/support/x;url=foo: Added.
     22
    1232016-09-03  Youenn Fablet  <youenn@apple.com>
    224
  • trunk/Source/WebCore/ChangeLog

    r205396 r205400  
     12016-09-03  Chris Dumez  <cdumez@apple.com>
     2
     3        Align meta element http-equiv="refresh" parsing with the HTML specification
     4        https://bugs.webkit.org/show_bug.cgi?id=161543
     5
     6        Reviewed by Darin Adler.
     7
     8        Align meta element http-equiv="refresh" parsing with the HTML specification:
     9        - https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-refresh
     10
     11        Tests: imported/w3c/web-platform-tests/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/parsing.html
     12
     13        * dom/Document.cpp:
     14        (WebCore::Document::processHttpEquiv):
     15        * html/parser/HTMLParserIdioms.cpp:
     16        (WebCore::parseHTTPRefreshInternal):
     17        (WebCore::parseMetaHTTPEquivRefresh):
     18        * html/parser/HTMLParserIdioms.h:
     19        * loader/FrameLoader.cpp:
     20        (WebCore::FrameLoader::receivedFirstData):
     21        * platform/network/HTTPParsers.cpp:
     22        (WebCore::skipWhiteSpace):
     23        (WebCore::skipEquals):
     24        (WebCore::parseHTTPRefresh):
     25        (WebCore::parseXSSProtectionHeader):
     26        (WebCore::skipValue): Deleted.
     27        * platform/network/HTTPParsers.h:
     28
    1292016-09-02  Myles C. Maxfield  <mmaxfield@apple.com>
    230
  • trunk/Source/WebCore/dom/Document.cpp

    r205340 r205400  
    32673267        double delay;
    32683268        String urlString;
    3269         if (frame && parseHTTPRefresh(content, true, delay, urlString)) {
     3269        if (frame && parseMetaHTTPEquivRefresh(content, delay, urlString)) {
    32703270            URL completedURL;
    32713271            if (urlString.isEmpty())
  • trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp

    r205095 r205400  
    292292}
    293293
    294 }
     294// https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-refresh
     295template <typename CharacterType>
     296static bool parseHTTPRefreshInternal(const CharacterType* position, const CharacterType* end, double& parsedDelay, String& parsedURL)
     297{
     298    while (position < end && isHTMLSpace(*position))
     299        ++position;
     300
     301    const CharacterType* numberStart = position;
     302    while (position < end && isASCIIDigit(*position))
     303        ++position;
     304
     305    Optional<int> number = parseHTMLNonNegativeInteger(StringView(numberStart, position - numberStart).toStringWithoutCopying());
     306    if (!number)
     307        return false;
     308
     309    while (position < end && (isASCIIDigit(*position) || *position == '.'))
     310        ++position;
     311
     312    if (position == end) {
     313        parsedDelay = number.value();
     314        return true;
     315    }
     316
     317    if (*position != ';' && *position != ',' && !isHTMLSpace(*position))
     318        return false;
     319
     320    parsedDelay = number.value();
     321
     322    while (position < end && isHTMLSpace(*position))
     323        ++position;
     324
     325    if (position < end && (*position == ';' || *position == ','))
     326        ++position;
     327
     328    while (position < end && isHTMLSpace(*position))
     329        ++position;
     330
     331    if (position == end)
     332        return true;
     333
     334    if (*position == 'U' || *position == 'u') {
     335        StringView url(position, end - position);
     336
     337        ++position;
     338
     339        if (position < end && (*position == 'R' || *position == 'r'))
     340            ++position;
     341        else {
     342            parsedURL = url.toString();
     343            return true;
     344        }
     345
     346        if (position < end && (*position == 'L' || *position == 'l'))
     347            ++position;
     348        else {
     349            parsedURL = url.toString();
     350            return true;
     351        }
     352
     353        while (position < end && isHTMLSpace(*position))
     354            ++position;
     355
     356        if (position < end && *position == '=')
     357            ++position;
     358        else {
     359            parsedURL = url.toString();
     360            return true;
     361        }
     362
     363        while (position < end && isHTMLSpace(*position))
     364            ++position;
     365    }
     366
     367    CharacterType quote;
     368    if (position < end && (*position == '\'' || *position == '"')) {
     369        quote = *position;
     370        ++position;
     371    } else
     372        quote = '\0';
     373
     374    StringView url(position, end - position);
     375
     376    if (quote != '\0') {
     377        size_t index = url.find(quote);
     378        if (index != notFound)
     379            url = url.substring(0, index);
     380    }
     381
     382    parsedURL = url.toString();
     383    return true;
     384}
     385
     386bool parseMetaHTTPEquivRefresh(const StringView& input, double& delay, String& url)
     387{
     388    if (LIKELY(input.is8Bit())) {
     389        auto* start = input.characters8();
     390        return parseHTTPRefreshInternal(start, start + input.length(), delay, url);
     391    }
     392
     393    auto* start = input.characters16();
     394    return parseHTTPRefreshInternal(start, start + input.length(), delay, url);
     395}
     396
     397}
  • trunk/Source/WebCore/html/parser/HTMLParserIdioms.h

    r205095 r205400  
    7070// https://html.spec.whatwg.org/multipage/infrastructure.html#rules-for-parsing-floating-point-number-values
    7171Vector<double> parseHTMLListOfOfFloatingPointNumberValues(StringView);
     72
     73// https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-refresh
     74bool parseMetaHTTPEquivRefresh(const StringView&, double& delay, String& url);
    7275
    7376// https://html.spec.whatwg.org/multipage/infrastructure.html#cors-settings-attribute
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r205275 r205400  
    656656    double delay;
    657657    String urlString;
    658     if (!parseHTTPRefresh(m_documentLoader->response().httpHeaderField(HTTPHeaderName::Refresh), false, delay, urlString))
     658    if (!parseHTTPRefresh(m_documentLoader->response().httpHeaderField(HTTPHeaderName::Refresh), delay, urlString))
    659659        return;
    660660    URL completedURL;
  • trunk/Source/WebCore/platform/network/HTTPParsers.cpp

    r205011 r205400  
    4848// true if there is more to parse, after incrementing pos past whitespace.
    4949// Note: Might return pos == str.length()
    50 static inline bool skipWhiteSpace(const String& str, unsigned& pos, bool fromHttpEquivMeta)
     50static inline bool skipWhiteSpace(const String& str, unsigned& pos)
    5151{
    5252    unsigned len = str.length();
    5353
    54     if (fromHttpEquivMeta) {
    55         while (pos < len && str[pos] <= ' ')
    56             ++pos;
    57     } else {
    58         while (pos < len && (str[pos] == '\t' || str[pos] == ' '))
    59             ++pos;
    60     }
     54    while (pos < len && (str[pos] == '\t' || str[pos] == ' '))
     55        ++pos;
    6156
    6257    return pos < len;
     
    8782static inline bool skipEquals(const String& str, unsigned &pos)
    8883{
    89     return skipWhiteSpace(str, pos, false) && str[pos++] == '=' && skipWhiteSpace(str, pos, false);
     84    return skipWhiteSpace(str, pos) && str[pos++] == '=' && skipWhiteSpace(str, pos);
    9085}
    9186
     
    188183}
    189184
    190 bool parseHTTPRefresh(const String& refresh, bool fromHttpEquivMeta, double& delay, String& url)
     185bool parseHTTPRefresh(const String& refresh, double& delay, String& url)
    191186{
    192187    unsigned len = refresh.length();
    193188    unsigned pos = 0;
    194189   
    195     if (!skipWhiteSpace(refresh, pos, fromHttpEquivMeta))
     190    if (!skipWhiteSpace(refresh, pos))
    196191        return false;
    197192   
     
    211206       
    212207        ++pos;
    213         skipWhiteSpace(refresh, pos, fromHttpEquivMeta);
     208        skipWhiteSpace(refresh, pos);
    214209        unsigned urlStartPos = pos;
    215210        if (refresh.find("url", urlStartPos, false) == urlStartPos) {
    216211            urlStartPos += 3;
    217             skipWhiteSpace(refresh, urlStartPos, fromHttpEquivMeta);
     212            skipWhiteSpace(refresh, urlStartPos);
    218213            if (refresh[urlStartPos] == '=') {
    219214                ++urlStartPos;
    220                 skipWhiteSpace(refresh, urlStartPos, fromHttpEquivMeta);
     215                skipWhiteSpace(refresh, urlStartPos);
    221216            } else
    222217                urlStartPos = pos;  // e.g. "Refresh: 0; url.html"
     
    389384    unsigned pos = 0;
    390385
    391     if (!skipWhiteSpace(header, pos, false))
     386    if (!skipWhiteSpace(header, pos))
    392387        return XSSProtectionDisposition::Enabled;
    393388
     
    406401    while (1) {
    407402        // At end of previous directive: consume whitespace, semicolon, and whitespace.
    408         if (!skipWhiteSpace(header, pos, false))
     403        if (!skipWhiteSpace(header, pos))
    409404            return result;
    410405
     
    415410        }
    416411
    417         if (!skipWhiteSpace(header, pos, false))
     412        if (!skipWhiteSpace(header, pos))
    418413            return result;
    419414
  • trunk/Source/WebCore/platform/network/HTTPParsers.h

    r203899 r205400  
    7979bool isValidHTTPHeaderValue(const String&);
    8080bool isValidHTTPToken(const String&);
    81 bool parseHTTPRefresh(const String& refresh, bool fromHttpEquivMeta, double& delay, String& url);
     81bool parseHTTPRefresh(const String& refresh, double& delay, String& url);
    8282Optional<std::chrono::system_clock::time_point> parseHTTPDate(const String&);
    8383String filenameFromHTTPContentDisposition(const String&);
Note: See TracChangeset for help on using the changeset viewer.