Changeset 84762 in webkit


Ignore:
Timestamp:
Apr 24, 2011 3:53:59 PM (13 years ago)
Author:
mjs@apple.com
Message:

2011-04-24 Maciej Stachowiak <mjs@apple.com>

Reviewed by George Staikos.

Handling of URLs like http:/example.com/ is incorrect
https://bugs.webkit.org/show_bug.cgi?id=59300
<rdar://problem/9231956>

URLs like http:/example.com/ or http:example.com/ are now correctly
canonicalized as http://example.com/


The code still doesn't quite match other browsers - at least some
other browsers seem to base parsing behavior on whether they
recongize a scheme from a fixed list, and ignore whether is
present in the URL or not.


  • platform/KURL.cpp: (WebCore::isNonFileHierarchicalScheme): New helper function. (WebCore::KURL::parse): For a particular list of whitelisted schemes, assume they are hierarchical and need an authority even if there is no after the :/

2011-04-24 Maciej Stachowiak <mjs@apple.com>

Reviewed by George Staikos.

Handling of URLs like http:/example.com/ is incorrect
https://bugs.webkit.org/show_bug.cgi?id=59300
<rdar://problem/9231956>


Added some new test cases. Also updated results for the
change. The changes are progressions.

  • fast/url/relative-expected.txt:
  • fast/url/script-tests/segments.js:
  • fast/url/script-tests/standard-url.js:
  • fast/url/segments-expected.txt:
  • fast/url/segments-from-data-url-expected.txt:
  • fast/url/standard-url-expected.txt:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r84761 r84762  
     12011-04-24  Maciej Stachowiak  <mjs@apple.com>
     2
     3        Reviewed by George Staikos.
     4
     5        Handling of URLs like http:/example.com/ is incorrect
     6        https://bugs.webkit.org/show_bug.cgi?id=59300
     7        <rdar://problem/9231956>
     8       
     9        Added some new test cases. Also updated results for the
     10        change. The changes are progressions.
     11
     12        * fast/url/relative-expected.txt:
     13        * fast/url/script-tests/segments.js:
     14        * fast/url/script-tests/standard-url.js:
     15        * fast/url/segments-expected.txt:
     16        * fast/url/segments-from-data-url-expected.txt:
     17        * fast/url/standard-url-expected.txt:
     18
    1192011-04-24  Adam Barth  <abarth@webkit.org>
    220
  • trunk/LayoutTests/fast/url/relative-expected.txt

    r78395 r84762  
    1414PASS canonicalize('http:path') is 'http://host/path'
    1515PASS canonicalize('http:path') is 'http://host/a/path'
    16 FAIL canonicalize('http:/path') should be http://host/path. Was http:/path.
     16FAIL canonicalize('http:/path') should be http://host/path. Was http://path/.
    1717FAIL canonicalize('HTTP:/path') should be http://host/path. Was http:/path.
    18 FAIL canonicalize('https:host2') should be https://host2/. Was https:host2.
     18PASS canonicalize('https:host2') is 'https://host2/'
    1919PASS canonicalize('htto:/host2') is 'htto:/host2'
    2020PASS canonicalize('/b/c/d') is 'http://host/b/c/d'
     
    4343PASS canonicalize('data:/base') is 'data:/base'
    4444PASS canonicalize('http://host/') is 'http://host/'
    45 FAIL canonicalize('http:host') should be http://host/. Was http:host.
     45PASS canonicalize('http:host') is 'http://host/'
    4646PASS canonicalize('./asd:fgh') is 'http://foo/asd:fgh'
    4747PASS canonicalize(':foo') is 'http://foo/:foo'
  • trunk/LayoutTests/fast/url/script-tests/segments.js

    r84756 r84762  
    7474  ["madeupscheme:/example.com/",             ["madeupscheme:","","0","/example.com/","",""]],
    7575  ["file:/example.com/",                     ["file:","","0","/example.com/","",""]],
    76   ["fops:/example.com/",                     ["fops:","","0","/example.com/","",""]],
     76  ["ftps:/example.com/",                     ["ftps:","","0","/example.com/","",""]],
    7777  ["gopher:/example.com/",                   ["gopher:","example.com","0","/","",""]],
    7878  ["ws:/example.com/",                       ["ws:","example.com","0","/","",""]],
     
    8181  ["javascript:/example.com/",               ["javascript:","","0","/example.com/","",""]],
    8282  ["mailto:/example.com/",                   ["mailto:","","0","/example.com/","",""]],
    83  
     83  ["http:example.com/",                      ["http:","example.org","0","/foo/example.com/","",""]],
     84  ["ftp:example.com/",                       ["ftp:","example.com","0","/","",""]],
     85  ["https:example.com/",                     ["https:","example.com","0","/","",""]],
     86  ["madeupscheme:example.com/",              ["madeupscheme:","","0","example.com/","",""]],
     87  ["file:example.com/",                      ["file:","","0","/example.com/","",""]],
     88  ["ftps:example.com/",                      ["ftps:","","0","example.com/","",""]],
     89  ["gopher:example.com/",                    ["gopher:","example.com","0","/","",""]],
     90  ["ws:example.com/",                        ["ws:","example.com","0","/","",""]],
     91  ["wss:example.com/",                       ["wss:","example.com","0","/","",""]],
     92  ["data:example.com/",                      ["data:","","0","example.com/","",""]],
     93  ["javascript:example.com/",                ["javascript:","","0","example.com/","",""]],
     94  ["mailto:example.com/",                    ["mailto:","","0","example.com/","",""]], 
    8495];
    8596
  • trunk/LayoutTests/fast/url/script-tests/standard-url.js

    r84756 r84762  
    4141  ["madeupscheme:/example.com/", "madeupscheme:/example.com/"],
    4242  ["file:/example.com/", "file://localhost/example.com/"],
    43   ["fops:/example.com/", "fops:/example.com/"],
     43  ["ftps:/example.com/", "ftps:/example.com/"],
    4444  ["gopher:/example.com/", "gopher://example.com/"],
    4545  ["ws:/example.com/", "ws://example.com/"],
     
    4848  ["javascript:/example.com/", "javascript:/example.com/"],
    4949  ["mailto:/example.com/", "mailto:/example.com/"],
     50  ["http:example.com/", "http://example.com/"],
     51  ["ftp:example.com/", "ftp://example.com/"],
     52  ["https:example.com/", "https://example.com/"],
     53  ["madeupscheme:example.com/", "madeupscheme:example.com/"],
     54  ["ftps:example.com/", "ftps:example.com/"],
     55  ["gopher:example.com/", "gopher://example.com/"],
     56  ["ws:example.com/", "ws://example.com/"],
     57  ["wss:example.com/", "wss://example.com/"],
     58  ["data:example.com/", "data:example.com/"],
     59  ["javascript:example.com/", "javascript:example.com/"],
     60  ["mailto:example.com/", "mailto:example.com/"],
    5061];
    5162
  • trunk/LayoutTests/fast/url/segments-expected.txt

    r84756 r84762  
    7070PASS segments('http://[2001::1]:80') is '["http:","[2001::1]","0","/","",""]'
    7171PASS segments('http://[[::]]') is '[":","","0","","",""]'
    72 FAIL segments('http:/example.com/') should be ["http:","example.org","0","/example.com/","",""]. Was ["http:","","0","/example.com/","",""].
    73 FAIL segments('ftp:/example.com/') should be ["ftp:","example.com","0","/","",""]. Was ["ftp:","","0","/example.com/","",""].
    74 FAIL segments('https:/example.com/') should be ["https:","example.com","0","/","",""]. Was ["https:","","0","/example.com/","",""].
     72FAIL segments('http:/example.com/') should be ["http:","example.org","0","/example.com/","",""]. Was ["http:","example.com","0","/","",""].
     73PASS segments('ftp:/example.com/') is '["ftp:","example.com","0","/","",""]'
     74PASS segments('https:/example.com/') is '["https:","example.com","0","/","",""]'
    7575PASS segments('madeupscheme:/example.com/') is '["madeupscheme:","","0","/example.com/","",""]'
    7676PASS segments('file:/example.com/') is '["file:","","0","/example.com/","",""]'
    77 PASS segments('fops:/example.com/') is '["fops:","","0","/example.com/","",""]'
    78 FAIL segments('gopher:/example.com/') should be ["gopher:","example.com","0","/","",""]. Was ["gopher:","","0","/example.com/","",""].
    79 FAIL segments('ws:/example.com/') should be ["ws:","example.com","0","/","",""]. Was ["ws:","","0","/example.com/","",""].
    80 FAIL segments('wss:/example.com/') should be ["wss:","example.com","0","/","",""]. Was ["wss:","","0","/example.com/","",""].
     77PASS segments('ftps:/example.com/') is '["ftps:","","0","/example.com/","",""]'
     78PASS segments('gopher:/example.com/') is '["gopher:","example.com","0","/","",""]'
     79PASS segments('ws:/example.com/') is '["ws:","example.com","0","/","",""]'
     80PASS segments('wss:/example.com/') is '["wss:","example.com","0","/","",""]'
    8181PASS segments('data:/example.com/') is '["data:","","0","/example.com/","",""]'
    8282PASS segments('javascript:/example.com/') is '["javascript:","","0","/example.com/","",""]'
    8383PASS segments('mailto:/example.com/') is '["mailto:","","0","/example.com/","",""]'
     84PASS segments('http:example.com/') is '["http:","example.org","0","/foo/example.com/","",""]'
     85PASS segments('ftp:example.com/') is '["ftp:","example.com","0","/","",""]'
     86PASS segments('https:example.com/') is '["https:","example.com","0","/","",""]'
     87PASS segments('madeupscheme:example.com/') is '["madeupscheme:","","0","example.com/","",""]'
     88FAIL segments('file:example.com/') should be ["file:","","0","/example.com/","",""]. Was ["file:","","0","example.com/","",""].
     89PASS segments('ftps:example.com/') is '["ftps:","","0","example.com/","",""]'
     90PASS segments('gopher:example.com/') is '["gopher:","example.com","0","/","",""]'
     91PASS segments('ws:example.com/') is '["ws:","example.com","0","/","",""]'
     92PASS segments('wss:example.com/') is '["wss:","example.com","0","/","",""]'
     93PASS segments('data:example.com/') is '["data:","","0","example.com/","",""]'
     94PASS segments('javascript:example.com/') is '["javascript:","","0","example.com/","",""]'
     95PASS segments('mailto:example.com/') is '["mailto:","","0","example.com/","",""]'
    8496PASS successfullyParsed is true
    8597
  • trunk/LayoutTests/fast/url/segments-from-data-url-expected.txt

    r78383 r84762  
    55
    66PASS segments('http://user:pass@foo:21/bar;par?b#c') is '["http:","foo","21","/bar;par","?b","#c"]'
    7 FAIL segments('http:foo.com') should be ["http:","foo.com","0","/","",""]. Was ["http:","","0","foo.com","",""].
     7PASS segments('http:foo.com') is '["http:","foo.com","0","/","",""]'
    88PASS segments('\t   :foo.com   \n') is '[":","","0","","",""]'
    99PASS segments(' foo.com  ') is '[":","","0","","",""]'
     
    4242PASS segments('foo://') is '["foo:","","0","//","",""]'
    4343PASS segments('http://a:b@c:29/d') is '["http:","c","29","/d","",""]'
    44 FAIL segments('http::@c:29') should be ["http:","c","29","/","",""]. Was ["http:","","0",":@c:29","",""].
     44PASS segments('http::@c:29') is '["http:","c","29","/","",""]'
    4545FAIL segments('http://&a:foo(b]c@d:2/') should be ["http:","d","2","/","",""]. Was [":","","0","","",""].
    4646FAIL segments('http://::@c@d:2') should be ["http:","d","2","/","",""]. Was [":","","0","","",""].
     
    6161FAIL segments('[61:24:74]:98') should be ["data:","","0","text/[61:24:74]:98","",""]. Was [":","","0","","",""].
    6262FAIL segments('http://[61:27]:98') should be [":","","0","","",""]. Was ["http:","[61:27]","98","/","",""].
    63 FAIL segments('http:[61:27]/:foo') should be [":","","0","","",""]. Was ["http:","","0","[61:27]/:foo","",""].
     63FAIL segments('http:[61:27]/:foo') should be [":","","0","","",""]. Was ["http:","[61:27]","0","/:foo","",""].
    6464PASS segments('http://[1::2]:3:4') is '[":","","0","","",""]'
    6565PASS segments('http://2001::1') is '[":","","0","","",""]'
  • trunk/LayoutTests/fast/url/standard-url-expected.txt

    r84756 r84762  
    3131PASS canonicalize('wss://foo:443/') is 'wss://foo/'
    3232PASS canonicalize('wss://foo:815/') is 'wss://foo:815/'
    33 FAIL canonicalize('http:/example.com/') should be http://example.com/. Was http:/example.com/.
    34 FAIL canonicalize('ftp:/example.com/') should be ftp://example.com/. Was ftp:/example.com/.
    35 FAIL canonicalize('https:/example.com/') should be https://example.com/. Was https:/example.com/.
     33PASS canonicalize('http:/example.com/') is 'http://example.com/'
     34PASS canonicalize('ftp:/example.com/') is 'ftp://example.com/'
     35PASS canonicalize('https:/example.com/') is 'https://example.com/'
    3636PASS canonicalize('madeupscheme:/example.com/') is 'madeupscheme:/example.com/'
    3737FAIL canonicalize('file:/example.com/') should be file://localhost/example.com/. Was file:///example.com/.
    38 PASS canonicalize('fops:/example.com/') is 'fops:/example.com/'
    39 FAIL canonicalize('gopher:/example.com/') should be gopher://example.com/. Was gopher:/example.com/.
    40 FAIL canonicalize('ws:/example.com/') should be ws://example.com/. Was ws:/example.com/.
    41 FAIL canonicalize('wss:/example.com/') should be wss://example.com/. Was wss:/example.com/.
     38PASS canonicalize('ftps:/example.com/') is 'ftps:/example.com/'
     39PASS canonicalize('gopher:/example.com/') is 'gopher://example.com/'
     40PASS canonicalize('ws:/example.com/') is 'ws://example.com/'
     41PASS canonicalize('wss:/example.com/') is 'wss://example.com/'
    4242PASS canonicalize('data:/example.com/') is 'data:/example.com/'
    4343PASS canonicalize('javascript:/example.com/') is 'javascript:/example.com/'
    4444PASS canonicalize('mailto:/example.com/') is 'mailto:/example.com/'
     45PASS canonicalize('http:example.com/') is 'http://example.com/'
     46PASS canonicalize('ftp:example.com/') is 'ftp://example.com/'
     47PASS canonicalize('https:example.com/') is 'https://example.com/'
     48PASS canonicalize('madeupscheme:example.com/') is 'madeupscheme:example.com/'
     49PASS canonicalize('ftps:example.com/') is 'ftps:example.com/'
     50PASS canonicalize('gopher:example.com/') is 'gopher://example.com/'
     51PASS canonicalize('ws:example.com/') is 'ws://example.com/'
     52PASS canonicalize('wss:example.com/') is 'wss://example.com/'
     53PASS canonicalize('data:example.com/') is 'data:example.com/'
     54PASS canonicalize('javascript:example.com/') is 'javascript:example.com/'
     55PASS canonicalize('mailto:example.com/') is 'mailto:example.com/'
    4556PASS successfullyParsed is true
    4657
  • trunk/Source/WebCore/ChangeLog

    r84760 r84762  
     12011-04-24  Maciej Stachowiak  <mjs@apple.com>
     2
     3        Reviewed by George Staikos.
     4
     5        Handling of URLs like http:/example.com/ is incorrect
     6        https://bugs.webkit.org/show_bug.cgi?id=59300
     7        <rdar://problem/9231956>
     8
     9        URLs like http:/example.com/ or http:example.com/ are now correctly
     10        canonicalized as http://example.com/
     11       
     12        The code still doesn't quite match other browsers - at least some
     13        other browsers seem to base parsing behavior on whether they
     14        recongize a scheme from a fixed list, and ignore whether // is
     15        present in the URL or not.
     16       
     17        * platform/KURL.cpp:
     18        (WebCore::isNonFileHierarchicalScheme): New helper function.
     19        (WebCore::KURL::parse): For a particular list of whitelisted schemes,
     20        assume they are hierarchical and need an authority even if there is no //
     21        after the :/
     22
    1232011-04-24  Dan Bernstein  <mitz@apple.com>
    224
  • trunk/Source/WebCore/platform/KURL.cpp

    r82181 r84762  
    11381138}
    11391139
     1140static bool isNonFileHierarchicalScheme(const char* scheme, size_t schemeLength)
     1141{
     1142    switch (schemeLength) {
     1143    case 2:
     1144        return equal("ws", 2, scheme, schemeLength);
     1145    case 3:
     1146        return equal("ftp", 3, scheme, schemeLength) || equal("wss", 3, scheme, schemeLength);
     1147    case 4:
     1148        return equal("http", 4, scheme, schemeLength);
     1149    case 5:
     1150        return equal("https", 5, scheme, schemeLength);
     1151    case 6:
     1152        return equal("gopher", 6, scheme, schemeLength);
     1153    }
     1154    return false;
     1155}
     1156
    11401157void KURL::parse(const char* url, const String* originalString)
    11411158{
     
    11741191
    11751192    bool hierarchical = url[schemeEnd + 1] == '/';
     1193    bool hasSecondSlash = hierarchical && url[schemeEnd + 2] == '/';
    11761194
    11771195    bool isFile = schemeEnd == 4
     
    11871205        && (url[4] == ':' || (matchLetter(url[4], 's') && url[5] == ':'));
    11881206
    1189     if (hierarchical && url[schemeEnd + 2] == '/') {
     1207    if ((hierarchical && hasSecondSlash) || isNonFileHierarchicalScheme(url, schemeEnd)) {
    11901208        // The part after the scheme is either a net_path or an abs_path whose first path segment is empty.
    11911209        // Attempt to find an authority.
    1192 
    11931210        // FIXME: Authority characters may be scanned twice, and it would be nice to be faster.
    1194         userStart += 2;
     1211
     1212        if (hierarchical)
     1213            userStart++;
     1214        if (hasSecondSlash)
     1215            userStart++;
    11951216        userEnd = userStart;
    11961217
     
    13951416
    13961417    // For canonicalization, ensure we have a '/' for no path.
    1397     // Do this only for hierarchical URL with protocol http or https.
    1398     if (m_protocolInHTTPFamily && hierarchical && pathEnd == pathStart)
     1418    // Do this only for URL with protocol http or https.
     1419    if (m_protocolInHTTPFamily && pathEnd == pathStart)
    13991420        *p++ = '/';
    14001421
Note: See TracChangeset for help on using the changeset viewer.