Changeset 267896 in webkit


Ignore:
Timestamp:
Oct 2, 2020 1:59:11 PM (4 years ago)
Author:
achristensen@apple.com
Message:

Copy host from base file URL
https://bugs.webkit.org/show_bug.cgi?id=217170

Reviewed by Brady Eidson.

LayoutTests/imported/w3c:

  • web-platform-tests/url/a-element-expected.txt:
  • web-platform-tests/url/a-element-xhtml-expected.txt:
  • web-platform-tests/url/resources/urltestdata.json:
  • web-platform-tests/url/url-constructor-expected.txt:

Source/WTF:

This matches Chrome and the URL specification.
Covered by newly passing web platform tests.

I also updated the web platform tests from https://github.com/web-platform-tests/wpt/pull/25716
which aligns with Safari in cases except copying of the host from base file URLs.

The implementation pushes copying from the base URL downstream in the parsing process to where it is in the URL specification
so that we can properly decide how much of the base URL to copy and so we can copy it into the right place in the result URL.

I also updated an assertion that makes sure that we re-use the input String if possible because there are cases where we copy
part of the parent URL, which is a "syntax violation" (meaning we copy the string parts and assemble a new one), then re-assemble
a new String that is equal to the input string. This is not a problem, it just needed to be reflected in the assertion.

  • wtf/URLParser.cpp:

(WTF::URLParser::URLParser):
(WTF::URLParser::parse):

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r267893 r267896  
     12020-10-02  Alex Christensen  <achristensen@webkit.org>
     2
     3        Copy host from base file URL
     4        https://bugs.webkit.org/show_bug.cgi?id=217170
     5
     6        Reviewed by Brady Eidson.
     7
     8        * web-platform-tests/url/a-element-expected.txt:
     9        * web-platform-tests/url/a-element-xhtml-expected.txt:
     10        * web-platform-tests/url/resources/urltestdata.json:
     11        * web-platform-tests/url/url-constructor-expected.txt:
     12
    1132020-10-02  Sam Weinig  <weinig@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/url/a-element-expected.txt

    r267837 r267896  
    418418PASS Parsing: <..> against <file:///>
    419419PASS Parsing: </> against <file:///C:/a/b>
     420PASS Parsing: </> against <file://h/C:/a/b>
     421PASS Parsing: </> against <file://h/a/b>
    420422PASS Parsing: <//d:> against <file:///C:/a/b>
    421423PASS Parsing: <//d:/..> against <file:///C:/a/b>
     
    428430PASS Parsing: <#x> against <file:///test?test#test>
    429431PASS Parsing: <file:#x> against <file:///test?test#test>
    430 FAIL Parsing: <file:\\//> against <about:blank> assert_equals: href expected "file:///" but got "file:////"
    431 FAIL Parsing: <file:\\\\> against <about:blank> assert_equals: href expected "file:///" but got "file:////"
    432 FAIL Parsing: <file:\\\\?fox> against <about:blank> assert_equals: href expected "file:///?fox" but got "file:////?fox"
    433 FAIL Parsing: <file:\\\\#guppy> against <about:blank> assert_equals: href expected "file:///#guppy" but got "file:////#guppy"
    434 FAIL Parsing: <file://spider///> against <about:blank> assert_equals: href expected "file://spider/" but got "file://spider///"
    435 FAIL Parsing: <file:\\localhost//> against <about:blank> assert_equals: href expected "file:///" but got "file:////"
     432PASS Parsing: <file:\\//> against <about:blank>
     433PASS Parsing: <file:\\\\> against <about:blank>
     434PASS Parsing: <file:\\\\?fox> against <about:blank>
     435PASS Parsing: <file:\\\\#guppy> against <about:blank>
     436PASS Parsing: <file://spider///> against <about:blank>
     437PASS Parsing: <file:\\localhost//> against <about:blank>
    436438PASS Parsing: <file:///localhost//cat> against <about:blank>
    437 FAIL Parsing: <file://\/localhost//cat> against <about:blank> assert_equals: href expected "file:///localhost//cat" but got "file:////localhost//cat"
    438 FAIL Parsing: <file://localhost//a//../..//> against <about:blank> assert_equals: href expected "file:///" but got "file://///"
    439 FAIL Parsing: </////mouse> against <file:///elephant> assert_equals: href expected "file:///mouse" but got "file://///mouse"
     439PASS Parsing: <file://\/localhost//cat> against <about:blank>
     440PASS Parsing: <file://localhost//a//../..//> against <about:blank>
     441PASS Parsing: </////mouse> against <file:///elephant>
    440442PASS Parsing: <\//pig> against <file://lion/>
    441 FAIL Parsing: <\/localhost//pig> against <file://lion/> assert_equals: href expected "file:///pig" but got "file:////pig"
    442 FAIL Parsing: <//localhost//pig> against <file://lion/> assert_equals: href expected "file:///pig" but got "file:////pig"
    443 FAIL Parsing: </..//localhost//pig> against <file://lion/> assert_equals: href expected "file://lion/localhost//pig" but got "file:////localhost//pig"
     443PASS Parsing: <\/localhost//pig> against <file://lion/>
     444PASS Parsing: <//localhost//pig> against <file://lion/>
     445PASS Parsing: </..//localhost//pig> against <file://lion/>
    444446PASS Parsing: <file://> against <file://ape/>
    445 FAIL Parsing: </rooibos> against <file://tea/> assert_equals: href expected "file://tea/rooibos" but got "file:///rooibos"
    446 FAIL Parsing: </?chai> against <file://tea/> assert_equals: href expected "file://tea/?chai" but got "file:///?chai"
    447 FAIL Parsing: <C|> against <file://host/dir/file> assert_equals: href expected "file:///C:" but got "file://host/dir/C|"
     447PASS Parsing: </rooibos> against <file://tea/>
     448PASS Parsing: </?chai> against <file://tea/>
     449FAIL Parsing: <C|> against <file://host/dir/file> assert_equals: href expected "file://host/C:" but got "file://host/dir/C|"
    448450PASS Parsing: <C|#> against <file://host/dir/file>
    449451PASS Parsing: <C|?> against <file://host/dir/file>
     
    458460PASS Parsing: <file:\c:\foo\bar> against <file:///c:/baz/qux>
    459461PASS Parsing: </c:/foo/bar> against <file://host/path>
    460 FAIL Parsing: <file://example.net/C:/> against <about:blank> assert_equals: href expected "file:///C:/" but got "file://example.net/C:/"
    461 FAIL Parsing: <file://1.2.3.4/C:/> against <about:blank> assert_equals: href expected "file:///C:/" but got "file://1.2.3.4/C:/"
    462 FAIL Parsing: <file://[1::8]/C:/> against <about:blank> assert_equals: href expected "file:///C:/" but got "file://[1::8]/C:/"
     462PASS Parsing: <file://example.net/C:/> against <about:blank>
     463PASS Parsing: <file://1.2.3.4/C:/> against <about:blank>
     464PASS Parsing: <file://[1::8]/C:/> against <about:blank>
    463465PASS Parsing: <file:/C|/> against <about:blank>
    464466PASS Parsing: <file://C|/> against <about:blank>
     
    476478PASS Parsing: <file:///./y:> against <about:blank>
    477479PASS Parsing: <\\\.\y:> against <about:blank>
     480PASS Parsing: <file://localhost//a//../..//foo> against <about:blank>
     481PASS Parsing: <file://localhost////foo> against <about:blank>
     482PASS Parsing: <file:////foo> against <about:blank>
     483PASS Parsing: <file:///one/two> against <file:///>
     484PASS Parsing: <file:////one/two> against <file:///>
     485PASS Parsing: <//one/two> against <file:///>
     486PASS Parsing: <///one/two> against <file:///>
     487PASS Parsing: <////one/two> against <file:///>
     488PASS Parsing: <file:///.//> against <file:////>
    478489PASS Parsing: <http://[1:0::]> against <http://example.net/>
    479490PASS Parsing: <http://[0:1:2:3:4:5:6:7:8]> against <http://example.net/>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/url/a-element-xhtml-expected.txt

    r267837 r267896  
    418418PASS Parsing: <..> against <file:///>
    419419PASS Parsing: </> against <file:///C:/a/b>
     420PASS Parsing: </> against <file://h/C:/a/b>
     421PASS Parsing: </> against <file://h/a/b>
    420422PASS Parsing: <//d:> against <file:///C:/a/b>
    421423PASS Parsing: <//d:/..> against <file:///C:/a/b>
     
    428430PASS Parsing: <#x> against <file:///test?test#test>
    429431PASS Parsing: <file:#x> against <file:///test?test#test>
    430 FAIL Parsing: <file:\\//> against <about:blank> assert_equals: href expected "file:///" but got "file:////"
    431 FAIL Parsing: <file:\\\\> against <about:blank> assert_equals: href expected "file:///" but got "file:////"
    432 FAIL Parsing: <file:\\\\?fox> against <about:blank> assert_equals: href expected "file:///?fox" but got "file:////?fox"
    433 FAIL Parsing: <file:\\\\#guppy> against <about:blank> assert_equals: href expected "file:///#guppy" but got "file:////#guppy"
    434 FAIL Parsing: <file://spider///> against <about:blank> assert_equals: href expected "file://spider/" but got "file://spider///"
    435 FAIL Parsing: <file:\\localhost//> against <about:blank> assert_equals: href expected "file:///" but got "file:////"
     432PASS Parsing: <file:\\//> against <about:blank>
     433PASS Parsing: <file:\\\\> against <about:blank>
     434PASS Parsing: <file:\\\\?fox> against <about:blank>
     435PASS Parsing: <file:\\\\#guppy> against <about:blank>
     436PASS Parsing: <file://spider///> against <about:blank>
     437PASS Parsing: <file:\\localhost//> against <about:blank>
    436438PASS Parsing: <file:///localhost//cat> against <about:blank>
    437 FAIL Parsing: <file://\/localhost//cat> against <about:blank> assert_equals: href expected "file:///localhost//cat" but got "file:////localhost//cat"
    438 FAIL Parsing: <file://localhost//a//../..//> against <about:blank> assert_equals: href expected "file:///" but got "file://///"
    439 FAIL Parsing: </////mouse> against <file:///elephant> assert_equals: href expected "file:///mouse" but got "file://///mouse"
     439PASS Parsing: <file://\/localhost//cat> against <about:blank>
     440PASS Parsing: <file://localhost//a//../..//> against <about:blank>
     441PASS Parsing: </////mouse> against <file:///elephant>
    440442PASS Parsing: <\//pig> against <file://lion/>
    441 FAIL Parsing: <\/localhost//pig> against <file://lion/> assert_equals: href expected "file:///pig" but got "file:////pig"
    442 FAIL Parsing: <//localhost//pig> against <file://lion/> assert_equals: href expected "file:///pig" but got "file:////pig"
    443 FAIL Parsing: </..//localhost//pig> against <file://lion/> assert_equals: href expected "file://lion/localhost//pig" but got "file:////localhost//pig"
     443PASS Parsing: <\/localhost//pig> against <file://lion/>
     444PASS Parsing: <//localhost//pig> against <file://lion/>
     445PASS Parsing: </..//localhost//pig> against <file://lion/>
    444446PASS Parsing: <file://> against <file://ape/>
    445 FAIL Parsing: </rooibos> against <file://tea/> assert_equals: href expected "file://tea/rooibos" but got "file:///rooibos"
    446 FAIL Parsing: </?chai> against <file://tea/> assert_equals: href expected "file://tea/?chai" but got "file:///?chai"
    447 FAIL Parsing: <C|> against <file://host/dir/file> assert_equals: href expected "file:///C:" but got "file://host/dir/C|"
     447PASS Parsing: </rooibos> against <file://tea/>
     448PASS Parsing: </?chai> against <file://tea/>
     449FAIL Parsing: <C|> against <file://host/dir/file> assert_equals: href expected "file://host/C:" but got "file://host/dir/C|"
    448450PASS Parsing: <C|#> against <file://host/dir/file>
    449451PASS Parsing: <C|?> against <file://host/dir/file>
     
    458460PASS Parsing: <file:\c:\foo\bar> against <file:///c:/baz/qux>
    459461PASS Parsing: </c:/foo/bar> against <file://host/path>
    460 FAIL Parsing: <file://example.net/C:/> against <about:blank> assert_equals: href expected "file:///C:/" but got "file://example.net/C:/"
    461 FAIL Parsing: <file://1.2.3.4/C:/> against <about:blank> assert_equals: href expected "file:///C:/" but got "file://1.2.3.4/C:/"
    462 FAIL Parsing: <file://[1::8]/C:/> against <about:blank> assert_equals: href expected "file:///C:/" but got "file://[1::8]/C:/"
     462PASS Parsing: <file://example.net/C:/> against <about:blank>
     463PASS Parsing: <file://1.2.3.4/C:/> against <about:blank>
     464PASS Parsing: <file://[1::8]/C:/> against <about:blank>
    463465PASS Parsing: <file:/C|/> against <about:blank>
    464466PASS Parsing: <file://C|/> against <about:blank>
     
    476478PASS Parsing: <file:///./y:> against <about:blank>
    477479PASS Parsing: <\\\.\y:> against <about:blank>
     480PASS Parsing: <file://localhost//a//../..//foo> against <about:blank>
     481PASS Parsing: <file://localhost////foo> against <about:blank>
     482PASS Parsing: <file:////foo> against <about:blank>
     483PASS Parsing: <file:///one/two> against <file:///>
     484PASS Parsing: <file:////one/two> against <file:///>
     485PASS Parsing: <//one/two> against <file:///>
     486PASS Parsing: <///one/two> against <file:///>
     487PASS Parsing: <////one/two> against <file:///>
     488PASS Parsing: <file:///.//> against <file:////>
    478489PASS Parsing: <http://[1:0::]> against <http://example.net/>
    479490PASS Parsing: <http://[0:1:2:3:4:5:6:7:8]> against <http://example.net/>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/url/resources/urltestdata.json

    r266399 r267896  
    52475247  },
    52485248  {
     5249    "input": "/",
     5250    "base": "file://h/C:/a/b",
     5251    "href": "file://h/C:/",
     5252    "protocol": "file:",
     5253    "username": "",
     5254    "password": "",
     5255    "host": "h",
     5256    "hostname": "h",
     5257    "port": "",
     5258    "pathname": "/C:/",
     5259    "search": "",
     5260    "hash": ""
     5261  },
     5262  {
     5263    "input": "/",
     5264    "base": "file://h/a/b",
     5265    "href": "file://h/",
     5266    "protocol": "file:",
     5267    "username": "",
     5268    "password": "",
     5269    "host": "h",
     5270    "hostname": "h",
     5271    "port": "",
     5272    "pathname": "/",
     5273    "search": "",
     5274    "hash": ""
     5275  },
     5276  {
    52495277    "input": "//d:",
    52505278    "base": "file:///C:/a/b",
     
    53905418    "input": "file:\\\\//",
    53915419    "base": "about:blank",
    5392     "href": "file:///",
    5393     "protocol": "file:",
    5394     "username": "",
    5395     "password": "",
    5396     "host": "",
    5397     "hostname": "",
    5398     "port": "",
    5399     "pathname": "/",
     5420    "href": "file:////",
     5421    "protocol": "file:",
     5422    "username": "",
     5423    "password": "",
     5424    "host": "",
     5425    "hostname": "",
     5426    "port": "",
     5427    "pathname": "//",
    54005428    "search": "",
    54015429    "hash": ""
     
    54045432    "input": "file:\\\\\\\\",
    54055433    "base": "about:blank",
    5406     "href": "file:///",
    5407     "protocol": "file:",
    5408     "username": "",
    5409     "password": "",
    5410     "host": "",
    5411     "hostname": "",
    5412     "port": "",
    5413     "pathname": "/",
     5434    "href": "file:////",
     5435    "protocol": "file:",
     5436    "username": "",
     5437    "password": "",
     5438    "host": "",
     5439    "hostname": "",
     5440    "port": "",
     5441    "pathname": "//",
    54145442    "search": "",
    54155443    "hash": ""
     
    54185446    "input": "file:\\\\\\\\?fox",
    54195447    "base": "about:blank",
    5420     "href": "file:///?fox",
    5421     "protocol": "file:",
    5422     "username": "",
    5423     "password": "",
    5424     "host": "",
    5425     "hostname": "",
    5426     "port": "",
    5427     "pathname": "/",
     5448    "href": "file:////?fox",
     5449    "protocol": "file:",
     5450    "username": "",
     5451    "password": "",
     5452    "host": "",
     5453    "hostname": "",
     5454    "port": "",
     5455    "pathname": "//",
    54285456    "search": "?fox",
    54295457    "hash": ""
     
    54325460    "input": "file:\\\\\\\\#guppy",
    54335461    "base": "about:blank",
    5434     "href": "file:///#guppy",
    5435     "protocol": "file:",
    5436     "username": "",
    5437     "password": "",
    5438     "host": "",
    5439     "hostname": "",
    5440     "port": "",
    5441     "pathname": "/",
     5462    "href": "file:////#guppy",
     5463    "protocol": "file:",
     5464    "username": "",
     5465    "password": "",
     5466    "host": "",
     5467    "hostname": "",
     5468    "port": "",
     5469    "pathname": "//",
    54425470    "search": "",
    54435471    "hash": "#guppy"
     
    54465474    "input": "file://spider///",
    54475475    "base": "about:blank",
    5448     "href": "file://spider/",
     5476    "href": "file://spider///",
    54495477    "protocol": "file:",
    54505478    "username": "",
     
    54535481    "hostname": "spider",
    54545482    "port": "",
    5455     "pathname": "/",
     5483    "pathname": "///",
    54565484    "search": "",
    54575485    "hash": ""
     
    54605488    "input": "file:\\\\localhost//",
    54615489    "base": "about:blank",
    5462     "href": "file:///",
    5463     "protocol": "file:",
    5464     "username": "",
    5465     "password": "",
    5466     "host": "",
    5467     "hostname": "",
    5468     "port": "",
    5469     "pathname": "/",
     5490    "href": "file:////",
     5491    "protocol": "file:",
     5492    "username": "",
     5493    "password": "",
     5494    "host": "",
     5495    "hostname": "",
     5496    "port": "",
     5497    "pathname": "//",
    54705498    "search": "",
    54715499    "hash": ""
     
    54885516    "input": "file://\\/localhost//cat",
    54895517    "base": "about:blank",
    5490     "href": "file:///localhost//cat",
    5491     "protocol": "file:",
    5492     "username": "",
    5493     "password": "",
    5494     "host": "",
    5495     "hostname": "",
    5496     "port": "",
    5497     "pathname": "/localhost//cat",
     5518    "href": "file:////localhost//cat",
     5519    "protocol": "file:",
     5520    "username": "",
     5521    "password": "",
     5522    "host": "",
     5523    "hostname": "",
     5524    "port": "",
     5525    "pathname": "//localhost//cat",
    54985526    "search": "",
    54995527    "hash": ""
     
    55025530    "input": "file://localhost//a//../..//",
    55035531    "base": "about:blank",
    5504     "href": "file:///",
    5505     "protocol": "file:",
    5506     "username": "",
    5507     "password": "",
    5508     "host": "",
    5509     "hostname": "",
    5510     "port": "",
    5511     "pathname": "/",
     5532    "href": "file://///",
     5533    "protocol": "file:",
     5534    "username": "",
     5535    "password": "",
     5536    "host": "",
     5537    "hostname": "",
     5538    "port": "",
     5539    "pathname": "///",
    55125540    "search": "",
    55135541    "hash": ""
     
    55165544    "input": "/////mouse",
    55175545    "base": "file:///elephant",
    5518     "href": "file:///mouse",
    5519     "protocol": "file:",
    5520     "username": "",
    5521     "password": "",
    5522     "host": "",
    5523     "hostname": "",
    5524     "port": "",
    5525     "pathname": "/mouse",
     5546    "href": "file://///mouse",
     5547    "protocol": "file:",
     5548    "username": "",
     5549    "password": "",
     5550    "host": "",
     5551    "hostname": "",
     5552    "port": "",
     5553    "pathname": "///mouse",
    55265554    "search": "",
    55275555    "hash": ""
     
    55445572    "input": "\\/localhost//pig",
    55455573    "base": "file://lion/",
    5546     "href": "file:///pig",
    5547     "protocol": "file:",
    5548     "username": "",
    5549     "password": "",
    5550     "host": "",
    5551     "hostname": "",
    5552     "port": "",
    5553     "pathname": "/pig",
     5574    "href": "file:////pig",
     5575    "protocol": "file:",
     5576    "username": "",
     5577    "password": "",
     5578    "host": "",
     5579    "hostname": "",
     5580    "port": "",
     5581    "pathname": "//pig",
    55545582    "search": "",
    55555583    "hash": ""
     
    55585586    "input": "//localhost//pig",
    55595587    "base": "file://lion/",
    5560     "href": "file:///pig",
    5561     "protocol": "file:",
    5562     "username": "",
    5563     "password": "",
    5564     "host": "",
    5565     "hostname": "",
    5566     "port": "",
    5567     "pathname": "/pig",
     5588    "href": "file:////pig",
     5589    "protocol": "file:",
     5590    "username": "",
     5591    "password": "",
     5592    "host": "",
     5593    "hostname": "",
     5594    "port": "",
     5595    "pathname": "//pig",
    55685596    "search": "",
    55695597    "hash": ""
     
    55725600    "input": "/..//localhost//pig",
    55735601    "base": "file://lion/",
    5574     "href": "file://lion/localhost//pig",
     5602    "href": "file://lion//localhost//pig",
    55755603    "protocol": "file:",
    55765604    "username": "",
     
    55795607    "hostname": "lion",
    55805608    "port": "",
    5581     "pathname": "/localhost//pig",
     5609    "pathname": "//localhost//pig",
    55825610    "search": "",
    55835611    "hash": ""
     
    56305658    "input": "C|",
    56315659    "base": "file://host/dir/file",
    5632     "href": "file:///C:",
    5633     "protocol": "file:",
    5634     "username": "",
    5635     "password": "",
    5636     "host": "",
    5637     "hostname": "",
     5660    "href": "file://host/C:",
     5661    "protocol": "file:",
     5662    "username": "",
     5663    "password": "",
     5664    "host": "host",
     5665    "hostname": "host",
    56385666    "port": "",
    56395667    "pathname": "/C:",
     
    56445672    "input": "C|#",
    56455673    "base": "file://host/dir/file",
    5646     "href": "file:///C:#",
    5647     "protocol": "file:",
    5648     "username": "",
    5649     "password": "",
    5650     "host": "",
    5651     "hostname": "",
     5674    "href": "file://host/C:#",
     5675    "protocol": "file:",
     5676    "username": "",
     5677    "password": "",
     5678    "host": "host",
     5679    "hostname": "host",
    56525680    "port": "",
    56535681    "pathname": "/C:",
     
    56585686    "input": "C|?",
    56595687    "base": "file://host/dir/file",
    5660     "href": "file:///C:?",
    5661     "protocol": "file:",
    5662     "username": "",
    5663     "password": "",
    5664     "host": "",
    5665     "hostname": "",
     5688    "href": "file://host/C:?",
     5689    "protocol": "file:",
     5690    "username": "",
     5691    "password": "",
     5692    "host": "host",
     5693    "hostname": "host",
    56665694    "port": "",
    56675695    "pathname": "/C:",
     
    56725700    "input": "C|/",
    56735701    "base": "file://host/dir/file",
    5674     "href": "file:///C:/",
    5675     "protocol": "file:",
    5676     "username": "",
    5677     "password": "",
    5678     "host": "",
    5679     "hostname": "",
     5702    "href": "file://host/C:/",
     5703    "protocol": "file:",
     5704    "username": "",
     5705    "password": "",
     5706    "host": "host",
     5707    "hostname": "host",
    56805708    "port": "",
    56815709    "pathname": "/C:/",
     
    56865714    "input": "C|\n/",
    56875715    "base": "file://host/dir/file",
    5688     "href": "file:///C:/",
    5689     "protocol": "file:",
    5690     "username": "",
    5691     "password": "",
    5692     "host": "",
    5693     "hostname": "",
     5716    "href": "file://host/C:/",
     5717    "protocol": "file:",
     5718    "username": "",
     5719    "password": "",
     5720    "host": "host",
     5721    "hostname": "host",
    56945722    "port": "",
    56955723    "pathname": "/C:/",
     
    57005728    "input": "C|\\",
    57015729    "base": "file://host/dir/file",
    5702     "href": "file:///C:/",
    5703     "protocol": "file:",
    5704     "username": "",
    5705     "password": "",
    5706     "host": "",
    5707     "hostname": "",
     5730    "href": "file://host/C:/",
     5731    "protocol": "file:",
     5732    "username": "",
     5733    "password": "",
     5734    "host": "host",
     5735    "hostname": "host",
    57085736    "port": "",
    57095737    "pathname": "/C:/",
     
    57855813    "input": "/c:/foo/bar",
    57865814    "base": "file://host/path",
    5787     "href": "file:///c:/foo/bar",
    5788     "protocol": "file:",
    5789     "username": "",
    5790     "password": "",
    5791     "host": "",
    5792     "hostname": "",
     5815    "href": "file://host/c:/foo/bar",
     5816    "protocol": "file:",
     5817    "username": "",
     5818    "password": "",
     5819    "host": "host",
     5820    "hostname": "host",
    57935821    "port": "",
    57945822    "pathname": "/c:/foo/bar",
     
    57965824    "hash": ""
    57975825  },
    5798   "# Windows drive letter quirk with not empty host",
     5826  "# Do not drop the host in the presence of a drive letter",
    57995827  {
    58005828    "input": "file://example.net/C:/",
    58015829    "base": "about:blank",
     5830    "href": "file://example.net/C:/",
     5831    "protocol": "file:",
     5832    "username": "",
     5833    "password": "",
     5834    "host": "example.net",
     5835    "hostname": "example.net",
     5836    "port": "",
     5837    "pathname": "/C:/",
     5838    "search": "",
     5839    "hash": ""
     5840  },
     5841  {
     5842    "input": "file://1.2.3.4/C:/",
     5843    "base": "about:blank",
     5844    "href": "file://1.2.3.4/C:/",
     5845    "protocol": "file:",
     5846    "username": "",
     5847    "password": "",
     5848    "host": "1.2.3.4",
     5849    "hostname": "1.2.3.4",
     5850    "port": "",
     5851    "pathname": "/C:/",
     5852    "search": "",
     5853    "hash": ""
     5854  },
     5855  {
     5856    "input": "file://[1::8]/C:/",
     5857    "base": "about:blank",
     5858    "href": "file://[1::8]/C:/",
     5859    "protocol": "file:",
     5860    "username": "",
     5861    "password": "",
     5862    "host": "[1::8]",
     5863    "hostname": "[1::8]",
     5864    "port": "",
     5865    "pathname": "/C:/",
     5866    "search": "",
     5867    "hash": ""
     5868  },
     5869  "# Windows drive letter quirk (no host)",
     5870  {
     5871    "input": "file:/C|/",
     5872    "base": "about:blank",
    58025873    "href": "file:///C:/",
    58035874    "protocol": "file:",
     
    58125883  },
    58135884  {
    5814     "input": "file://1.2.3.4/C:/",
     5885    "input": "file://C|/",
    58155886    "base": "about:blank",
    58165887    "href": "file:///C:/",
     
    58255896    "hash": ""
    58265897  },
    5827   {
    5828     "input": "file://[1::8]/C:/",
    5829     "base": "about:blank",
    5830     "href": "file:///C:/",
    5831     "protocol": "file:",
    5832     "username": "",
    5833     "password": "",
    5834     "host": "",
    5835     "hostname": "",
    5836     "port": "",
    5837     "pathname": "/C:/",
    5838     "search": "",
    5839     "hash": ""
    5840   },
    5841   "# Windows drive letter quirk (no host)",
    5842   {
    5843     "input": "file:/C|/",
    5844     "base": "about:blank",
    5845     "href": "file:///C:/",
    5846     "protocol": "file:",
    5847     "username": "",
    5848     "password": "",
    5849     "host": "",
    5850     "hostname": "",
    5851     "port": "",
    5852     "pathname": "/C:/",
    5853     "search": "",
    5854     "hash": ""
    5855   },
    5856   {
    5857     "input": "file://C|/",
    5858     "base": "about:blank",
    5859     "href": "file:///C:/",
    5860     "protocol": "file:",
    5861     "username": "",
    5862     "password": "",
    5863     "host": "",
    5864     "hostname": "",
    5865     "port": "",
    5866     "pathname": "/C:/",
    5867     "search": "",
    5868     "hash": ""
    5869   },
    58705898  "# file URLs without base URL by Rimas Misevičius",
    58715899  {
     
    60346062    "base": "about:blank",
    60356063    "failure": true
     6064  },
     6065  "# Additional file URL tetsts for (https://github.com/whatwg/url/issues/405)",
     6066  {
     6067    "input": "file://localhost//a//../..//foo",
     6068    "base": "about:blank",
     6069    "href": "file://///foo",
     6070    "protocol": "file:",
     6071    "username": "",
     6072    "password": "",
     6073    "host": "",
     6074    "hostname": "",
     6075    "port": "",
     6076    "pathname": "///foo",
     6077    "search": "",
     6078    "hash": ""
     6079  },
     6080  {
     6081    "input": "file://localhost////foo",
     6082    "base": "about:blank",
     6083    "href": "file://////foo",
     6084    "protocol": "file:",
     6085    "username": "",
     6086    "password": "",
     6087    "host": "",
     6088    "hostname": "",
     6089    "port": "",
     6090    "pathname": "////foo",
     6091    "search": "",
     6092    "hash": ""
     6093  },
     6094  {
     6095    "input": "file:////foo",
     6096    "base": "about:blank",
     6097    "href": "file:////foo",
     6098    "protocol": "file:",
     6099    "username": "",
     6100    "password": "",
     6101    "host": "",
     6102    "hostname": "",
     6103    "port": "",
     6104    "pathname": "//foo",
     6105    "search": "",
     6106    "hash": ""
     6107  },
     6108  {
     6109    "input": "file:///one/two",
     6110    "base": "file:///",
     6111    "href": "file:///one/two",
     6112    "protocol": "file:",
     6113    "username": "",
     6114    "password": "",
     6115    "host": "",
     6116    "hostname": "",
     6117    "port": "",
     6118    "pathname": "/one/two",
     6119    "search": "",
     6120    "hash": ""
     6121  },
     6122  {
     6123    "input": "file:////one/two",
     6124    "base": "file:///",
     6125    "href": "file:////one/two",
     6126    "protocol": "file:",
     6127    "username": "",
     6128    "password": "",
     6129    "host": "",
     6130    "hostname": "",
     6131    "port": "",
     6132    "pathname": "//one/two",
     6133    "search": "",
     6134    "hash": ""
     6135  },
     6136  {
     6137    "input": "//one/two",
     6138    "base": "file:///",
     6139    "href": "file://one/two",
     6140    "protocol": "file:",
     6141    "username": "",
     6142    "password": "",
     6143    "host": "one",
     6144    "hostname": "one",
     6145    "port": "",
     6146    "pathname": "/two",
     6147    "search": "",
     6148    "hash": ""
     6149  },
     6150  {
     6151    "input": "///one/two",
     6152    "base": "file:///",
     6153    "href": "file:///one/two",
     6154    "protocol": "file:",
     6155    "username": "",
     6156    "password": "",
     6157    "host": "",
     6158    "hostname": "",
     6159    "port": "",
     6160    "pathname": "/one/two",
     6161    "search": "",
     6162    "hash": ""
     6163  },
     6164  {
     6165    "input": "////one/two",
     6166    "base": "file:///",
     6167    "href": "file:////one/two",
     6168    "protocol": "file:",
     6169    "username": "",
     6170    "password": "",
     6171    "host": "",
     6172    "hostname": "",
     6173    "port": "",
     6174    "pathname": "//one/two",
     6175    "search": "",
     6176    "hash": ""
     6177  },
     6178  {
     6179    "input": "file:///.//",
     6180    "base": "file:////",
     6181    "href": "file:////",
     6182    "protocol": "file:",
     6183    "username": "",
     6184    "password": "",
     6185    "host": "",
     6186    "hostname": "",
     6187    "port": "",
     6188    "pathname": "//",
     6189    "search": "",
     6190    "hash": ""
    60366191  },
    60376192  "# IPv6 tests",
  • trunk/LayoutTests/imported/w3c/web-platform-tests/url/url-constructor-expected.txt

    r267837 r267896  
    421421PASS Parsing: <..> against <file:///>
    422422PASS Parsing: </> against <file:///C:/a/b>
     423PASS Parsing: </> against <file://h/C:/a/b>
     424PASS Parsing: </> against <file://h/a/b>
    423425PASS Parsing: <//d:> against <file:///C:/a/b>
    424426PASS Parsing: <//d:/..> against <file:///C:/a/b>
     
    431433PASS Parsing: <#x> against <file:///test?test#test>
    432434PASS Parsing: <file:#x> against <file:///test?test#test>
    433 FAIL Parsing: <file:\\//> against <about:blank> assert_equals: href expected "file:///" but got "file:////"
    434 FAIL Parsing: <file:\\\\> against <about:blank> assert_equals: href expected "file:///" but got "file:////"
    435 FAIL Parsing: <file:\\\\?fox> against <about:blank> assert_equals: href expected "file:///?fox" but got "file:////?fox"
    436 FAIL Parsing: <file:\\\\#guppy> against <about:blank> assert_equals: href expected "file:///#guppy" but got "file:////#guppy"
    437 FAIL Parsing: <file://spider///> against <about:blank> assert_equals: href expected "file://spider/" but got "file://spider///"
    438 FAIL Parsing: <file:\\localhost//> against <about:blank> assert_equals: href expected "file:///" but got "file:////"
     435PASS Parsing: <file:\\//> against <about:blank>
     436PASS Parsing: <file:\\\\> against <about:blank>
     437PASS Parsing: <file:\\\\?fox> against <about:blank>
     438PASS Parsing: <file:\\\\#guppy> against <about:blank>
     439PASS Parsing: <file://spider///> against <about:blank>
     440PASS Parsing: <file:\\localhost//> against <about:blank>
    439441PASS Parsing: <file:///localhost//cat> against <about:blank>
    440 FAIL Parsing: <file://\/localhost//cat> against <about:blank> assert_equals: href expected "file:///localhost//cat" but got "file:////localhost//cat"
    441 FAIL Parsing: <file://localhost//a//../..//> against <about:blank> assert_equals: href expected "file:///" but got "file://///"
    442 FAIL Parsing: </////mouse> against <file:///elephant> assert_equals: href expected "file:///mouse" but got "file://///mouse"
     442PASS Parsing: <file://\/localhost//cat> against <about:blank>
     443PASS Parsing: <file://localhost//a//../..//> against <about:blank>
     444PASS Parsing: </////mouse> against <file:///elephant>
    443445PASS Parsing: <\//pig> against <file://lion/>
    444 FAIL Parsing: <\/localhost//pig> against <file://lion/> assert_equals: href expected "file:///pig" but got "file:////pig"
    445 FAIL Parsing: <//localhost//pig> against <file://lion/> assert_equals: href expected "file:///pig" but got "file:////pig"
    446 FAIL Parsing: </..//localhost//pig> against <file://lion/> assert_equals: href expected "file://lion/localhost//pig" but got "file:////localhost//pig"
     446PASS Parsing: <\/localhost//pig> against <file://lion/>
     447PASS Parsing: <//localhost//pig> against <file://lion/>
     448PASS Parsing: </..//localhost//pig> against <file://lion/>
    447449PASS Parsing: <file://> against <file://ape/>
    448 FAIL Parsing: </rooibos> against <file://tea/> assert_equals: href expected "file://tea/rooibos" but got "file:///rooibos"
    449 FAIL Parsing: </?chai> against <file://tea/> assert_equals: href expected "file://tea/?chai" but got "file:///?chai"
    450 FAIL Parsing: <C|> against <file://host/dir/file> assert_equals: href expected "file:///C:" but got "file://host/dir/C|"
     450PASS Parsing: </rooibos> against <file://tea/>
     451PASS Parsing: </?chai> against <file://tea/>
     452FAIL Parsing: <C|> against <file://host/dir/file> assert_equals: href expected "file://host/C:" but got "file://host/dir/C|"
    451453PASS Parsing: <C|#> against <file://host/dir/file>
    452454PASS Parsing: <C|?> against <file://host/dir/file>
     
    461463PASS Parsing: <file:\c:\foo\bar> against <file:///c:/baz/qux>
    462464PASS Parsing: </c:/foo/bar> against <file://host/path>
    463 FAIL Parsing: <file://example.net/C:/> against <about:blank> assert_equals: href expected "file:///C:/" but got "file://example.net/C:/"
    464 FAIL Parsing: <file://1.2.3.4/C:/> against <about:blank> assert_equals: href expected "file:///C:/" but got "file://1.2.3.4/C:/"
    465 FAIL Parsing: <file://[1::8]/C:/> against <about:blank> assert_equals: href expected "file:///C:/" but got "file://[1::8]/C:/"
     465PASS Parsing: <file://example.net/C:/> against <about:blank>
     466PASS Parsing: <file://1.2.3.4/C:/> against <about:blank>
     467PASS Parsing: <file://[1::8]/C:/> against <about:blank>
    466468PASS Parsing: <file:/C|/> against <about:blank>
    467469PASS Parsing: <file://C|/> against <about:blank>
     
    479481PASS Parsing: <file:///./y:> against <about:blank>
    480482PASS Parsing: <\\\.\y:> against <about:blank>
     483PASS Parsing: <file://localhost//a//../..//foo> against <about:blank>
     484PASS Parsing: <file://localhost////foo> against <about:blank>
     485PASS Parsing: <file:////foo> against <about:blank>
     486PASS Parsing: <file:///one/two> against <file:///>
     487PASS Parsing: <file:////one/two> against <file:///>
     488PASS Parsing: <//one/two> against <file:///>
     489PASS Parsing: <///one/two> against <file:///>
     490PASS Parsing: <////one/two> against <file:///>
     491PASS Parsing: <file:///.//> against <file:////>
    481492PASS Parsing: <http://[1:0::]> against <http://example.net/>
    482493PASS Parsing: <http://[0:1:2:3:4:5:6:7:8]> against <http://example.net/>
  • trunk/Source/WTF/ChangeLog

    r267870 r267896  
     12020-10-02  Alex Christensen  <achristensen@webkit.org>
     2
     3        Copy host from base file URL
     4        https://bugs.webkit.org/show_bug.cgi?id=217170
     5
     6        Reviewed by Brady Eidson.
     7
     8        This matches Chrome and the URL specification.
     9        Covered by newly passing web platform tests.
     10
     11        I also updated the web platform tests from https://github.com/web-platform-tests/wpt/pull/25716
     12        which aligns with Safari in cases except copying of the host from base file URLs.
     13
     14        The implementation pushes copying from the base URL downstream in the parsing process to where it is in the URL specification
     15        so that we can properly decide how much of the base URL to copy and so we can copy it into the right place in the result URL.
     16
     17        I also updated an assertion that makes sure that we re-use the input String if possible because there are cases where we copy
     18        part of the parent URL, which is a "syntax violation" (meaning we copy the string parts and assemble a new one), then re-assemble
     19        a new String that is equal to the input string.  This is not a problem, it just needed to be reflected in the assertion.
     20
     21        * wtf/URLParser.cpp:
     22        (WTF::URLParser::URLParser):
     23        (WTF::URLParser::parse):
     24
    1252020-10-02  Youenn Fablet  <youenn@apple.com>
    226
  • trunk/Source/WTF/wtf/URLParser.cpp

    r267837 r267896  
    10751075    ASSERT(!m_url.m_isValid
    10761076        || m_didSeeSyntaxViolation == (m_url.string() != input)
    1077         || (input.isAllSpecialCharacters<isC0ControlOrSpace>()
    1078             && m_url.m_string == base.m_string.left(base.m_queryEnd)));
     1077        || (input.isAllSpecialCharacters<isC0ControlOrSpace>() && m_url.m_string == base.m_string.left(base.m_queryEnd))
     1078        || (base.isValid() && base.protocolIs("file")));
    10791079    ASSERT(internalValuesConsistent(m_url));
    10801080#if ASSERT_ENABLED
     
    12661266                break;
    12671267            }
    1268             copyURLPartsUntil(base, URLPart::SchemeEnd, c, nonUTF8QueryEncoding);
    1269             appendToASCIIBuffer(':');
    12701268            state = State::File;
    12711269            break;
     
    15301528                    copyURLPartsUntil(base, URLPart::PathAfterLastSlash, c, nonUTF8QueryEncoding);
    15311529                else {
    1532                     appendToASCIIBuffer("///", 3);
    1533                     m_url.m_userStart = currentPosition(c) - 1;
    1534                     m_url.m_userEnd = m_url.m_userStart;
    1535                     m_url.m_passwordEnd = m_url.m_userStart;
    1536                     m_url.m_hostEnd = m_url.m_userStart;
    1537                     m_url.m_portLength = 0;
    1538                     m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
     1530                    bool copiedHost = false;
     1531                    if (base.isValid() && base.protocolIs("file")) {
     1532                        if (base.host().isEmpty()) {
     1533                            copyURLPartsUntil(base, URLPart::SchemeEnd, c, nonUTF8QueryEncoding);
     1534                            appendToASCIIBuffer(":///", 4);
     1535                        } else {
     1536                            copyURLPartsUntil(base, URLPart::PortEnd, c, nonUTF8QueryEncoding);
     1537                            appendToASCIIBuffer('/');
     1538                            copiedHost = true;
     1539                        }
     1540                    } else
     1541                        appendToASCIIBuffer("///", 3);
     1542                    if (!copiedHost) {
     1543                        m_url.m_userStart = currentPosition(c) - 1;
     1544                        m_url.m_userEnd = m_url.m_userStart;
     1545                        m_url.m_passwordEnd = m_url.m_userStart;
     1546                        m_url.m_hostEnd = m_url.m_userStart;
     1547                        m_url.m_portLength = 0;
     1548                    }
     1549                    m_url.m_pathAfterLastSlash = m_url.m_hostEnd + 1;
    15391550                    if (isWindowsDriveLetter(c))
    15401551                        appendWindowsDriveLetter(c);
     
    15491560                if (UNLIKELY(*c == '\\'))
    15501561                    syntaxViolation(c);
     1562                if (base.isValid() && base.protocolIs("file")) {
     1563                    copyURLPartsUntil(base, URLPart::SchemeEnd, c, nonUTF8QueryEncoding);
     1564                    appendToASCIIBuffer(":/", 2);
     1565                }
    15511566                appendToASCIIBuffer('/');
    15521567                advance(c);
     
    15601575                break;
    15611576            }
    1562             syntaxViolation(c);
    1563             appendToASCIIBuffer("//", 2);
    1564             m_url.m_userStart = currentPosition(c) - 1;
    1565             m_url.m_userEnd = m_url.m_userStart;
    1566             m_url.m_passwordEnd = m_url.m_userStart;
    1567             m_url.m_hostEnd = m_url.m_userStart;
    1568             m_url.m_portLength = 0;
     1577            {
     1578                bool copiedHost = false;
     1579                if (base.isValid() && base.protocolIs("file")) {
     1580                    if (base.host().isEmpty()) {
     1581                        copyURLPartsUntil(base, URLPart::SchemeEnd, c, nonUTF8QueryEncoding);
     1582                        appendToASCIIBuffer(":///", 4);
     1583                    } else {
     1584                        copyURLPartsUntil(base, URLPart::PortEnd, c, nonUTF8QueryEncoding);
     1585                        appendToASCIIBuffer('/');
     1586                        copiedHost = true;
     1587                    }
     1588                } else {
     1589                    syntaxViolation(c);
     1590                    appendToASCIIBuffer("//", 2);
     1591                }
     1592                if (!copiedHost) {
     1593                    m_url.m_userStart = currentPosition(c) - 1;
     1594                    m_url.m_userEnd = m_url.m_userStart;
     1595                    m_url.m_passwordEnd = m_url.m_userStart;
     1596                    m_url.m_hostEnd = m_url.m_userStart;
     1597                    m_url.m_portLength = 0;
     1598                }
     1599            }
    15691600            if (isWindowsDriveLetter(c)) {
    15701601                appendWindowsDriveLetter(c);
    1571                 m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
     1602                m_url.m_pathAfterLastSlash = m_url.m_hostEnd + 1;
    15721603            } else if (copyBaseWindowsDriveLetter(base)) {
    15731604                appendToASCIIBuffer('/');
    1574                 m_url.m_pathAfterLastSlash = m_url.m_userStart + 4;
     1605                m_url.m_pathAfterLastSlash = m_url.m_hostEnd + 4;
    15751606            } else
    1576                 m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
     1607                m_url.m_pathAfterLastSlash = m_url.m_hostEnd + 1;
    15771608            state = State::Path;
    15781609            break;
     
    18651896        LOG_FINAL_STATE("FileSlash");
    18661897        syntaxViolation(c);
    1867         m_url.m_userStart = currentPosition(c) + 1;
    1868         appendToASCIIBuffer("//", 2);
    1869         m_url.m_userEnd = m_url.m_userStart;
    1870         m_url.m_passwordEnd = m_url.m_userStart;
    1871         m_url.m_hostEnd = m_url.m_userStart;
    1872         m_url.m_portLength = 0;
     1898        {
     1899            bool copiedHost = false;
     1900            if (base.isValid() && base.protocolIs("file")) {
     1901                if (base.host().isEmpty()) {
     1902                    copyURLPartsUntil(base, URLPart::SchemeEnd, c, nonUTF8QueryEncoding);
     1903                    appendToASCIIBuffer(":/", 2);
     1904                } else {
     1905                    copyURLPartsUntil(base, URLPart::PortEnd, c, nonUTF8QueryEncoding);
     1906                    appendToASCIIBuffer('/');
     1907                    copiedHost = true;
     1908                }
     1909            }
     1910            if (!copiedHost) {
     1911                m_url.m_userStart = currentPosition(c) + 1;
     1912                appendToASCIIBuffer("//", 2);
     1913                m_url.m_userEnd = m_url.m_userStart;
     1914                m_url.m_passwordEnd = m_url.m_userStart;
     1915                m_url.m_hostEnd = m_url.m_userStart;
     1916                m_url.m_portLength = 0;
     1917            }
     1918        }
    18731919        if (copyBaseWindowsDriveLetter(base)) {
    18741920            appendToASCIIBuffer('/');
    1875             m_url.m_pathAfterLastSlash = m_url.m_userStart + 4;
     1921            m_url.m_pathAfterLastSlash = m_url.m_hostEnd + 4;
    18761922        } else
    1877             m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
     1923            m_url.m_pathAfterLastSlash = m_url.m_hostEnd + 1;
    18781924        m_url.m_pathEnd = m_url.m_pathAfterLastSlash;
    18791925        m_url.m_queryEnd = m_url.m_pathAfterLastSlash;
     
    19572003        m_url.m_string = String::adopt(WTFMove(m_asciiBuffer));
    19582004    m_url.m_isValid = true;
    1959     URL_PARSER_LOG("Parsed URL <%s>", m_url.m_string.utf8().data());
     2005    URL_PARSER_LOG("Parsed URL <%s>\n\n", m_url.m_string.utf8().data());
    19602006}
    19612007
Note: See TracChangeset for help on using the changeset viewer.