Changeset 248895 in webkit


Ignore:
Timestamp:
Aug 20, 2019 12:04:02 AM (5 years ago)
Author:
Devin Rousso
Message:

Web Inspector: Use URL constructor to better handle all kinds of URLs
https://bugs.webkit.org/show_bug.cgi?id=165155

Reviewed by Joseph Pecoraro.

Source/WebInspectorUI:

  • UserInterface/Base/URLUtilities.js:

(parseURL):

LayoutTests:

  • inspector/unit-tests/url-utilities.html:
  • inspector/unit-tests/url-utilities-expected.txt:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r248894 r248895  
     12019-08-20  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Use URL constructor to better handle all kinds of URLs
     4        https://bugs.webkit.org/show_bug.cgi?id=165155
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        * inspector/unit-tests/url-utilities.html:
     9        * inspector/unit-tests/url-utilities-expected.txt:
     10
    1112019-08-19  Devin Rousso  <drousso@apple.com>
    212
  • trunk/LayoutTests/inspector/unit-tests/url-utilities-expected.txt

    r248774 r248895  
    1717PASS: port should be: 'null'
    1818PASS: origin should be: 'http://example.com'
    19 PASS: path should be: 'null'
     19PASS: path should be: '/'
    2020PASS: queryString should be: 'null'
    2121PASS: fragment should be: 'null'
     
    3737PASS: userinfo should be: 'null'
    3838PASS: host should be: 'example.com'
    39 PASS: port should be: '80'
    40 PASS: origin should be: 'http://example.com:80'
     39PASS: port should be: 'null'
     40PASS: origin should be: 'http://example.com'
     41PASS: path should be: '/'
     42PASS: queryString should be: 'null'
     43PASS: fragment should be: 'null'
     44PASS: lastPathComponent should be: 'null'
     45
     46Test Valid: http://example.com:42/
     47PASS: scheme should be: 'http'
     48PASS: userinfo should be: 'null'
     49PASS: host should be: 'example.com'
     50PASS: port should be: '42'
     51PASS: origin should be: 'http://example.com:42'
    4152PASS: path should be: '/'
    4253PASS: queryString should be: 'null'
     
    6273PASS: origin should be: 'http://example.com'
    6374PASS: path should be: '/path/to/page.html'
    64 PASS: queryString should be: ''
     75PASS: queryString should be: 'null'
    6576PASS: fragment should be: 'null'
    6677PASS: lastPathComponent should be: 'page.html'
     
    127138PASS: port should be: 'null'
    128139PASS: origin should be: 'http://example.com'
    129 PASS: path should be: 'null'
     140PASS: path should be: '/'
    130141PASS: queryString should be: 'null'
    131142PASS: fragment should be: 'alpha/beta'
     
    149160PASS: port should be: 'null'
    150161PASS: origin should be: 'http://example'
    151 PASS: path should be: 'null'
     162PASS: path should be: '/'
    152163PASS: queryString should be: 'null'
    153164PASS: fragment should be: 'null'
     
    160171PASS: port should be: 'null'
    161172PASS: origin should be: 'http://my.example.com'
    162 PASS: path should be: 'null'
     173PASS: path should be: '/'
    163174PASS: queryString should be: 'null'
    164175PASS: fragment should be: 'null'
     
    176187PASS: lastPathComponent should be: 'null'
    177188
    178 -- Known issues <https://webkit.org/b/165155>
    179 
    180189Test Invalid: http://
    181 FAIL: Should not be a complete URL
    182     Expected: truthy
    183     Actual: false
     190PASS: Should not be a complete URL
    184191PASS: URL constructor thinks this is invalid
    185192
    186 Test Invalid: http://example.com:999999999
    187 FAIL: Should not be a complete URL
    188     Expected: truthy
    189     Actual: false
     193Test Invalid: http://example.com:65537
     194PASS: Should not be a complete URL
    190195PASS: URL constructor thinks this is invalid
    191196
    192197Test Valid: http:example.com/
    193 FAIL: scheme should be: 'http'
    194     Expected: "http"
    195     Actual: null
    196 PASS: userinfo should be: 'null'
    197 FAIL: host should be: 'example.com'
    198     Expected: "example.com"
    199     Actual: null
    200 PASS: port should be: 'null'
    201 FAIL: origin should be: 'http://example.com'
    202     Expected: "http://example.com"
    203     Actual: null
    204 FAIL: path should be: '/'
    205     Expected: "/"
    206     Actual: null
     198PASS: scheme should be: 'http'
     199PASS: userinfo should be: 'null'
     200PASS: host should be: 'example.com'
     201PASS: port should be: 'null'
     202PASS: origin should be: 'http://example.com'
     203PASS: path should be: '/'
    207204PASS: queryString should be: 'null'
    208205PASS: fragment should be: 'null'
     
    210207
    211208Test Valid: http:/example.com/
    212 FAIL: scheme should be: 'http'
    213     Expected: "http"
    214     Actual: null
    215 PASS: userinfo should be: 'null'
    216 FAIL: host should be: 'example.com'
    217     Expected: "example.com"
    218     Actual: null
    219 PASS: port should be: 'null'
    220 FAIL: origin should be: 'http://example.com'
    221     Expected: "http://example.com"
    222     Actual: null
    223 FAIL: path should be: '/'
    224     Expected: "/"
    225     Actual: null
     209PASS: scheme should be: 'http'
     210PASS: userinfo should be: 'null'
     211PASS: host should be: 'example.com'
     212PASS: port should be: 'null'
     213PASS: origin should be: 'http://example.com'
     214PASS: path should be: '/'
    226215PASS: queryString should be: 'null'
    227216PASS: fragment should be: 'null'
     
    239228PASS: lastPathComponent should be: 'null'
    240229
    241 Test Valid: http://user@pass:example.com/
    242 FAIL: scheme should be: 'http'
    243     Expected: "http"
    244     Actual: null
    245 PASS: userinfo should be: 'null'
    246 FAIL: host should be: 'example.com'
    247     Expected: "example.com"
    248     Actual: null
    249 PASS: port should be: 'null'
    250 FAIL: origin should be: 'http://example.com'
    251     Expected: "http://example.com"
    252     Actual: null
    253 FAIL: path should be: '/'
    254     Expected: "/"
    255     Actual: null
    256 PASS: queryString should be: 'null'
    257 PASS: fragment should be: 'null'
    258 PASS: lastPathComponent should be: 'null'
     230Test Valid: http://:pass@example.com/
     231PASS: scheme should be: 'http'
     232PASS: userinfo should be: ':pass'
     233PASS: host should be: 'example.com'
     234PASS: port should be: 'null'
     235PASS: origin should be: 'http://example.com'
     236PASS: path should be: '/'
     237PASS: queryString should be: 'null'
     238PASS: fragment should be: 'null'
     239PASS: lastPathComponent should be: 'null'
     240
     241Test Invalid: http://user@pass:example.com/
     242PASS: Should not be a complete URL
     243PASS: URL constructor thinks this is invalid
    259244
    260245Test Valid: http://example.com?key=alpha/beta
    261246PASS: scheme should be: 'http'
    262247PASS: userinfo should be: 'null'
    263 FAIL: host should be: 'example.com'
    264     Expected: "example.com"
    265     Actual: "example.com?key=alpha"
    266 PASS: port should be: 'null'
    267 FAIL: origin should be: 'http://example.com'
    268     Expected: "http://example.com"
    269     Actual: "http://example.com?key=alpha"
    270 FAIL: path should be: 'null'
    271     Expected: null
    272     Actual: "/beta"
    273 FAIL: queryString should be: 'key=alpha/beta'
    274     Expected: "key=alpha/beta"
    275     Actual: null
    276 PASS: fragment should be: 'null'
    277 FAIL: lastPathComponent should be: 'null'
    278     Expected: null
    279     Actual: "beta"
     248PASS: host should be: 'example.com'
     249PASS: port should be: 'null'
     250PASS: origin should be: 'http://example.com'
     251PASS: path should be: '/'
     252PASS: queryString should be: 'key=alpha/beta'
     253PASS: fragment should be: 'null'
     254PASS: lastPathComponent should be: 'null'
    280255
    281256-- Running test case: parseDataURL
     
    381356
    382357-- Running test case: WI.displayNameForURL
    383 PASS: Display name of 'a' should be 'a'.
    384 PASS: Display name of 'http://' should be 'http://'.
    385358PASS: Display name of 'http://example' should be 'example'.
    386359PASS: Display name of 'http://example.com' should be 'example.com'.
    387360PASS: Display name of 'http://example.com/' should be 'example.com'.
    388 PASS: Display name of 'http://example.com:999999999' should be 'example.com'.
    389361PASS: Display name of 'http://example.com:80/' should be 'example.com'.
     362PASS: Display name of 'http://example.com:42/' should be 'example.com'.
    390363PASS: Display name of 'http://example.com/path' should be 'path'.
    391364PASS: Display name of 'http://example.com/path/' should be 'path'.
     
    402375PASS: Display name of 'http://example.com/#foo%20bar' should be 'example.com'.
    403376PASS: Display name of 'http://example.com/foo%20bar' should be 'foo bar'.
     377PASS: Display name of 'http://example.com?key=foo%20bar' should be 'example.com'.
    404378PASS: Display name of 'http://example.com/?key=foo%20bar' should be 'example.com'.
     379PASS: Display name of 'http://example.com?key=foo bar' should be 'example.com'.
     380PASS: Display name of 'http://example.com/?key=foo bar' should be 'example.com'.
    405381PASS: Display name of 'http://example.com/foo%20bar' should be 'foo bar'.
    406382PASS: Display name of 'http://example.com/foo bar' should be 'foo bar'.
     
    409385PASS: Display name of 'http://example.com#foo%2Fbar' should be 'example.com'.
    410386PASS: Display name of 'http://example.com/#foo%2Fbar' should be 'example.com'.
     387PASS: Display name of 'http://example.com?key=foo%2Fbar' should be 'example.com'.
    411388PASS: Display name of 'http://example.com/?key=foo%2Fbar' should be 'example.com'.
     389PASS: Display name of 'http://example.com?key=foo/bar' should be 'example.com'.
     390PASS: Display name of 'http://example.com/?key=foo/bar' should be 'example.com'.
    412391PASS: Display name of 'http://example.com/foo%2Fbar' should be 'foo/bar'.
    413392PASS: Display name of 'http://user:pass@example.com/' should be 'example.com'.
     393PASS: Display name of 'http://:pass@example.com/' should be 'example.com'.
    414394PASS: Display name of 'http://my.example.com' should be 'my.example.com'.
    415395PASS: Display name of 'http://my.example.com/' should be 'my.example.com'.
     
    423403PASS: Display name of 'app-specific://example.com/' should be 'example.com'.
    424404PASS: Display name of 'app-specific://example.com/path' should be 'path'.
    425 
    426 Allowing directory as name...
    427405PASS: Display name of 'a' should be 'a'.
    428406PASS: Display name of 'http://' should be 'http://'.
    429 PASS: Display name of 'http://example' should be 'example'.
    430 PASS: Display name of 'http://example.com' should be 'example.com'.
     407PASS: Display name of 'http://example.com:65537' should be 'http://example.com:65537'.
     408PASS: Display name of 'http://user@pass:example.com/' should be 'http://user@pass:example.com/'.
     409
     410Allowing directory as name...
     411PASS: Display name of 'http://example' should be '/'.
     412PASS: Display name of 'http://example.com' should be '/'.
    431413PASS: Display name of 'http://example.com/' should be '/'.
    432 PASS: Display name of 'http://example.com:999999999' should be 'example.com'.
    433414PASS: Display name of 'http://example.com:80/' should be '/'.
     415PASS: Display name of 'http://example.com:42/' should be '/'.
    434416PASS: Display name of 'http://example.com/path' should be 'path'.
    435417PASS: Display name of 'http://example.com/path/' should be '/'.
     
    443425PASS: Display name of 'http://example.com/path/to/page.html?a=1&b=foo%2Fbar#test' should be 'page.html'.
    444426PASS: Display name of 'http://example.com:123/path/to/page.html?a=1&b=foo%2Fbar#test' should be 'page.html'.
    445 PASS: Display name of 'http://example.com#foo%20bar' should be 'example.com'.
     427PASS: Display name of 'http://example.com#foo%20bar' should be '/'.
    446428PASS: Display name of 'http://example.com/#foo%20bar' should be '/'.
    447429PASS: Display name of 'http://example.com/foo%20bar' should be 'foo bar'.
     430PASS: Display name of 'http://example.com?key=foo%20bar' should be '/'.
    448431PASS: Display name of 'http://example.com/?key=foo%20bar' should be '/'.
     432PASS: Display name of 'http://example.com?key=foo bar' should be '/'.
     433PASS: Display name of 'http://example.com/?key=foo bar' should be '/'.
    449434PASS: Display name of 'http://example.com/foo%20bar' should be 'foo bar'.
    450435PASS: Display name of 'http://example.com/foo bar' should be 'foo bar'.
    451 PASS: Display name of 'http://example.com#foo/bar' should be 'example.com'.
     436PASS: Display name of 'http://example.com#foo/bar' should be '/'.
    452437PASS: Display name of 'http://example.com/#foo/bar' should be '/'.
    453 PASS: Display name of 'http://example.com#foo%2Fbar' should be 'example.com'.
     438PASS: Display name of 'http://example.com#foo%2Fbar' should be '/'.
    454439PASS: Display name of 'http://example.com/#foo%2Fbar' should be '/'.
     440PASS: Display name of 'http://example.com?key=foo%2Fbar' should be '/'.
    455441PASS: Display name of 'http://example.com/?key=foo%2Fbar' should be '/'.
     442PASS: Display name of 'http://example.com?key=foo/bar' should be '/'.
     443PASS: Display name of 'http://example.com/?key=foo/bar' should be '/'.
    456444PASS: Display name of 'http://example.com/foo%2Fbar' should be 'foo/bar'.
    457445PASS: Display name of 'http://user:pass@example.com/' should be '/'.
    458 PASS: Display name of 'http://my.example.com' should be 'my.example.com'.
     446PASS: Display name of 'http://:pass@example.com/' should be '/'.
     447PASS: Display name of 'http://my.example.com' should be '/'.
    459448PASS: Display name of 'http://my.example.com/' should be '/'.
    460449PASS: Display name of 'file:///foo' should be 'foo'.
     
    467456PASS: Display name of 'app-specific://example.com/' should be '/'.
    468457PASS: Display name of 'app-specific://example.com/path' should be 'path'.
    469 
    470 -- Known issues <https://webkit.org/b/165155>
    471 
    472 FAIL: Display name of 'http://example.com?key=foo%2Fbar' should be 'example.com'.
    473     Expected: "example.com"
    474     Actual: "example.com?key=foo%2fbar"
    475 FAIL: Display name of 'http://example.com?key=foo/bar' should be 'example.com'.
    476     Expected: "example.com"
    477     Actual: "bar"
    478 FAIL: Display name of 'http://example.com?key=foo%20bar' should be 'example.com'.
    479     Expected: "example.com"
    480     Actual: "example.com?key=foo%20bar"
    481 FAIL: Display name of 'http://example.com?key=foo bar' should be 'example.com'.
    482     Expected: "example.com"
    483     Actual: "example.com?key=foo bar"
    484 
    485 Allowing directory as name...
    486 FAIL: Display name of 'http://example.com?key=foo%2Fbar' should be 'example.com'.
    487     Expected: "example.com"
    488     Actual: "example.com?key=foo%2fbar"
    489 FAIL: Display name of 'http://example.com?key=foo/bar' should be 'example.com'.
    490     Expected: "example.com"
    491     Actual: "bar"
    492 FAIL: Display name of 'http://example.com?key=foo%20bar' should be 'example.com'.
    493     Expected: "example.com"
    494     Actual: "example.com?key=foo%20bar"
    495 FAIL: Display name of 'http://example.com?key=foo bar' should be 'example.com'.
    496     Expected: "example.com"
    497     Actual: "example.com?key=foo bar"
     458PASS: Display name of 'a' should be 'a'.
     459PASS: Display name of 'http://' should be 'http://'.
     460PASS: Display name of 'http://example.com:65537' should be 'http://example.com:65537'.
     461PASS: Display name of 'http://user@pass:example.com/' should be 'http://user@pass:example.com/'.
    498462
    499463-- Running test case: WI.h2Authority
     
    513477PASS: HTTP/2 :authority of 'http://user:pass@example.com:123/foo' should be 'example.com:123'.
    514478PASS: HTTP/2 :authority of 'https://user:pass@example.com:123/foo' should be 'example.com:123'.
     479PASS: HTTP/2 :authority of 'ftp://:pass@example.com/foo' should be ':pass@example.com'.
     480PASS: HTTP/2 :authority of 'http://:pass@example.com/foo' should be 'example.com'.
     481PASS: HTTP/2 :authority of 'https://:pass@example.com/foo' should be 'example.com'.
     482PASS: HTTP/2 :authority of 'ftp://:pass@example.com:123/foo' should be ':pass@example.com:123'.
     483PASS: HTTP/2 :authority of 'http://:pass@example.com:123/foo' should be 'example.com:123'.
     484PASS: HTTP/2 :authority of 'https://:pass@example.com:123/foo' should be 'example.com:123'.
    515485
    516486-- Running test case: WI.h2Path
    517487PASS: HTTP/2 :path of 'http://example.com' should be '/'.
    518488PASS: HTTP/2 :path of 'https://example.com' should be '/'.
    519 PASS: HTTP/2 :path of 'ftp://example.com' should be ''.
     489PASS: HTTP/2 :path of 'ftp://example.com' should be '/'.
    520490PASS: HTTP/2 :path of 'http://example.com/foo' should be '/foo'.
    521491PASS: HTTP/2 :path of 'https://example.com/foo' should be '/foo'.
  • trunk/LayoutTests/inspector/unit-tests/url-utilities.html

    r248774 r248895  
    1414                InspectorTest.log("");
    1515                InspectorTest.log("Test Invalid: " + url);
    16                 InspectorTest.expectThat(parseURL(url).scheme === null, "Should not be a complete URL");
     16
     17                let urlComponents = parseURL(url);
     18                InspectorTest.expectNull(urlComponents.scheme, "Should not be a complete URL");
     19                if (urlComponents.scheme)
     20                    InspectorTest.json(urlComponents);
    1721
    1822                try {
     
    5155                port: null,
    5256                origin: "http://example.com",
    53                 path: null,
     57                path: "/",
    5458                queryString: null,
    5559                fragment: null,
     
    7377                userinfo: null,
    7478                host: "example.com",
    75                 port: 80,
    76                 origin: "http://example.com:80",
     79                port: null,
     80                origin: "http://example.com",
     81                path: "/",
     82                queryString: null,
     83                fragment: null,
     84                lastPathComponent: null,
     85            });
     86
     87            testValid("http://example.com:42/", {
     88                scheme: "http",
     89                userinfo: null,
     90                host: "example.com",
     91                port: 42,
     92                origin: "http://example.com:42",
    7793                path: "/",
    7894                queryString: null,
     
    100116                origin: "http://example.com",
    101117                path: "/path/to/page.html",
    102                 queryString: "",
     118                queryString: null,
    103119                fragment: null,
    104120                lastPathComponent: "page.html",
     
    171187                port: null,
    172188                origin: "http://example.com",
    173                 path: null,
     189                path: "/",
    174190                queryString: null,
    175191                fragment: "alpha/beta",
     
    195211                port: null,
    196212                origin: "http://example",
    197                 path: null,
     213                path: "/",
    198214                queryString: null,
    199215                fragment: null,
     
    207223                port: null,
    208224                origin: "http://my.example.com",
    209                 path: null,
     225                path: "/",
    210226                queryString: null,
    211227                fragment: null,
     
    226242            });
    227243
    228             // FIXME: <https://webkit.org/b/165155> Web Inspector: Use URL constructor to better handle all kinds of URLs
    229             InspectorTest.log("");
    230             InspectorTest.log("-- Known issues <https://webkit.org/b/165155>");
    231 
    232244            testInvalid("http://");
    233             testInvalid("http://example.com:999999999");
     245            testInvalid("http://example.com:65537");
    234246
    235247            testValid("http:example.com/", {
     
    269281            });
    270282
    271             testValid("http://user@pass:example.com/", {
    272                 scheme: "http",
    273                 userinfo: null,
    274                 host: "example.com",
    275                 port: null,
    276                 origin: "http://example.com",
    277                 path: "/",
    278                 queryString: null,
    279                 fragment: null,
    280                 lastPathComponent: null,
    281             });
     283            testValid("http://:pass@example.com/", {
     284                scheme: "http",
     285                userinfo: ":pass",
     286                host: "example.com",
     287                port: null,
     288                origin: "http://example.com",
     289                path: "/",
     290                queryString: null,
     291                fragment: null,
     292                lastPathComponent: null,
     293            });
     294
     295            testInvalid("http://user@pass:example.com/");
    282296
    283297            testValid("http://example.com?key=alpha/beta", {
     
    287301                port: null,
    288302                origin: "http://example.com",
    289                 path: null,
     303                path: "/",
    290304                queryString: "key=alpha/beta",
    291305                fragment: null,
     
    444458        test() {
    445459            function test(tests) {
    446                 for (let {url, expected} of tests)
     460                for (let {url, expected} of tests) {
     461                    expected = expected || url;
    447462                    InspectorTest.expectEqual(WI.displayNameForURL(url), expected, `Display name of '${url}' should be '${expected}'.`);
     463                }
    448464
    449465                InspectorTest.newline();
    450466
    451467                InspectorTest.log("Allowing directory as name...");
    452                 for (let {url, expected, directory} of tests)
    453                     InspectorTest.expectEqual(WI.displayNameForURL(url, null, {allowDirectoryAsName: true}), directory || expected, `Display name of '${url}' should be '${directory || expected}'.`);
     468                for (let {url, expected, directory} of tests) {
     469                    expected = directory || expected || url;
     470                    InspectorTest.expectEqual(WI.displayNameForURL(url, null, {allowDirectoryAsName: true}), expected, `Display name of '${url}' should be '${expected}'.`);
     471                }
    454472            }
    455473
    456474            test([
    457                 {url: "a", expected: "a"},
    458 
    459                 {url: "http://", expected: "http://"},
    460                 {url: "http://example", expected: "example"},
    461                 {url: "http://example.com", expected: "example.com"},
     475                {url: "http://example", expected: "example", directory: "/"},
     476                {url: "http://example.com", expected: "example.com", directory: "/"},
    462477                {url: "http://example.com/", expected: "example.com", directory: "/"},
    463                 {url: "http://example.com:999999999", expected: "example.com"},
    464478                {url: "http://example.com:80/", expected: "example.com", directory: "/"},
     479                {url: "http://example.com:42/", expected: "example.com", directory: "/"},
    465480                {url: "http://example.com/path", expected: "path"},
    466481                {url: "http://example.com/path/", expected: "path", directory: "/"},
     
    475490                {url: "http://example.com:123/path/to/page.html?a=1&b=foo%2Fbar#test", expected: "page.html"},
    476491
    477                 {url: "http://example.com#foo%20bar", expected: "example.com"},
     492                {url: "http://example.com#foo%20bar", expected: "example.com", directory: "/"},
    478493                {url: "http://example.com/#foo%20bar", expected: "example.com", directory: "/"},
    479494                {url: "http://example.com/foo%20bar", expected: "foo bar"},
     495                {url: "http://example.com?key=foo%20bar", expected: "example.com", directory: "/"},
    480496                {url: "http://example.com/?key=foo%20bar", expected: "example.com", directory: "/"},
     497                {url: "http://example.com?key=foo bar", expected: "example.com", directory: "/"},
     498                {url: "http://example.com/?key=foo bar", expected: "example.com", directory: "/"},
    481499                {url: "http://example.com/foo%20bar", expected: "foo bar"},
    482500                {url: "http://example.com/foo bar", expected: "foo bar"},
    483501
    484                 {url: "http://example.com#foo/bar", expected: "example.com"},
     502                {url: "http://example.com#foo/bar", expected: "example.com", directory: "/"},
    485503                {url: "http://example.com/#foo/bar", expected: "example.com", directory: "/"},
    486                 {url: "http://example.com#foo%2Fbar", expected: "example.com"},
     504                {url: "http://example.com#foo%2Fbar", expected: "example.com", directory: "/"},
    487505                {url: "http://example.com/#foo%2Fbar", expected: "example.com", directory: "/"},
     506                {url: "http://example.com?key=foo%2Fbar", expected: "example.com", directory: "/"},
    488507                {url: "http://example.com/?key=foo%2Fbar", expected: "example.com", directory: "/"},
     508                {url: "http://example.com?key=foo/bar", expected: "example.com", directory: "/"},
     509                {url: "http://example.com/?key=foo/bar", expected: "example.com", directory: "/"},
    489510                {url: "http://example.com/foo%2Fbar", expected: "foo/bar"},
    490511
    491512                {url: "http://user:pass@example.com/", expected: "example.com", directory: "/"},
    492 
    493                 {url: "http://my.example.com", expected: "my.example.com"},
     513                {url: "http://:pass@example.com/", expected: "example.com", directory: "/"},
     514
     515                {url: "http://my.example.com", expected: "my.example.com", directory: "/"},
    494516                {url: "http://my.example.com/", expected: "my.example.com", directory: "/"},
    495517
     
    506528                {url: "app-specific://example.com/", expected: "example.com", directory: "/"},
    507529                {url: "app-specific://example.com/path", expected: "path"},
    508             ]);
    509 
    510             // FIXME: <https://webkit.org/b/165155> Web Inspector: Use URL constructor to better handle all kinds of URLs
    511             InspectorTest.newline();
    512             InspectorTest.log("-- Known issues <https://webkit.org/b/165155>");
    513             InspectorTest.newline();
    514 
    515             test([
    516                 {url: "http://example.com?key=foo%2Fbar", expected: "example.com"},
    517                 {url: "http://example.com?key=foo/bar", expected: "example.com"},
    518 
    519                 {url: "http://example.com?key=foo%20bar", expected: "example.com"},
    520                 {url: "http://example.com?key=foo bar", expected: "example.com"},
     530
     531                // Invalid
     532                {url: "a"},
     533                {url: "http://"},
     534                {url: "http://example.com:65537"},
     535                {url: "http://user@pass:example.com/"},
    521536            ]);
    522537        },
     
    551566            test("https://user:pass@example.com:123/foo", "example.com:123");
    552567
     568            test("ftp://:pass@example.com/foo", ":pass@example.com");
     569            test("http://:pass@example.com/foo", "example.com");
     570            test("https://:pass@example.com/foo", "example.com");
     571
     572            test("ftp://:pass@example.com:123/foo", ":pass@example.com:123");
     573            test("http://:pass@example.com:123/foo", "example.com:123");
     574            test("https://:pass@example.com:123/foo", "example.com:123");
     575
    553576            return true;
    554577        }
     
    565588            test("http://example.com", "/");
    566589            test("https://example.com", "/");
    567             test("ftp://example.com", "");
     590            test("ftp://example.com", "/");
    568591
    569592            test("http://example.com/foo", "/foo");
  • trunk/Source/WebInspectorUI/ChangeLog

    r248894 r248895  
     12019-08-20  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Use URL constructor to better handle all kinds of URLs
     4        https://bugs.webkit.org/show_bug.cgi?id=165155
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        * UserInterface/Base/URLUtilities.js:
     9        (parseURL):
     10
    1112019-08-19  Devin Rousso  <drousso@apple.com>
    212
  • trunk/Source/WebInspectorUI/UserInterface/Base/URLUtilities.js

    r248753 r248895  
    2424 */
    2525
    26 // FIXME: <https://webkit.org/b/165155> Web Inspector: Use URL constructor to better handle all kinds of URLs
    27 
    2826function removeURLFragment(url)
    2927{
     
    9492function parseURL(url)
    9593{
    96     url = url ? url.trim() : "";
    97 
    98     if (url.startsWith("data:"))
    99         return {scheme: "data", userinfo: null, host: null, port: null, origin: null, path: null, queryString: null, fragment: null, lastPathComponent: null};
    100 
    101     let match = url.match(/^(?<scheme>[^\/:]+):\/\/(?:(?<userinfo>[^#@\/]+)@)?(?<host>[^\/#:]*)(?::(?<port>[\d]+))?(?:(?<path>\/[^#]*)?(?:#(?<fragment>.*))?)?$/i);
    102     if (!match)
    103         return {scheme: null, userinfo: null, host: null, port: null, origin: null, path: null, queryString: null, fragment: null, lastPathComponent: null};
    104 
    105     let scheme = match.groups.scheme.toLowerCase();
    106     let userinfo = match.groups.userinfo || null;
    107     let host = match.groups.host.toLowerCase();
    108     let port = Number(match.groups.port) || null;
    109     let wholePath = match.groups.path || null;
    110     let fragment = match.groups.fragment || null;
    111     let path = wholePath;
    112     let queryString = null;
    113 
    114     // Split the path and the query string.
    115     if (wholePath) {
    116         let indexOfQuery = wholePath.indexOf("?");
    117         if (indexOfQuery !== -1) {
    118             path = wholePath.substring(0, indexOfQuery);
    119             queryString = wholePath.substring(indexOfQuery + 1);
    120         }
    121         path = resolveDotsInPath(path);
    122     }
     94    let result = {
     95        scheme: null,
     96        userinfo: null,
     97        host: null,
     98        port: null,
     99        origin: null,
     100        path: null,
     101        queryString: null,
     102        fragment: null,
     103        lastPathComponent: null,
     104    };
     105
     106    // dataURLs should be handled by `parseDataURL`.
     107    if (url && url.startsWith("data:")) {
     108        result.scheme = "data";
     109        return result;
     110    }
     111
     112    let parsed = null;
     113    try {
     114        parsed = new URL(url);
     115    } catch {
     116        return result;
     117    }
     118
     119    result.scheme = parsed.protocol.slice(0, -1); // remove trailing ":"
     120
     121    if (parsed.username)
     122        result.userinfo = parsed.username;
     123    if (parsed.password)
     124        result.userinfo = (result.userinfo || "") + ":" + parsed.password;
     125
     126    if (parsed.hostname)
     127        result.host = parsed.hostname;
     128
     129    if (parsed.port)
     130        result.port = Number(parsed.port);
     131
     132    if (parsed.origin)
     133        result.origin = parsed.origin;
     134    else if (result.scheme && result.host) {
     135        result.origin = result.scheme + "://" + result.host;
     136        if (result.port)
     137            result.origin += ":" + result.port;
     138    }
     139
     140    if (parsed.pathname)
     141        result.path = parsed.pathname;
     142
     143    if (parsed.search)
     144        result.queryString = parsed.search.substring(1); // remove leading "?"
     145
     146    if (parsed.hash)
     147        result.fragment = parsed.hash.substring(1); // remove leading "#"
    123148
    124149    // Find last path component.
    125     let lastPathComponent = null;
    126     if (path && path !== "/") {
     150    if (result.path && result.path !== "/") {
    127151        // Skip the trailing slash if there is one.
    128         let endOffset = path[path.length - 1] === "/" ? 1 : 0;
    129         let lastSlashIndex = path.lastIndexOf("/", path.length - 1 - endOffset);
     152        let endOffset = result.path.endsWith("/") ? 1 : 0;
     153        let lastSlashIndex = result.path.lastIndexOf("/", result.path.length - 1 - endOffset);
    130154        if (lastSlashIndex !== -1)
    131             lastPathComponent = path.substring(lastSlashIndex + 1, path.length - endOffset);
    132     }
    133 
    134     let origin = null;
    135     if (scheme && host) {
    136         origin = scheme + "://" + host;
    137         if (port)
    138             origin += ":" + port;
    139     }
    140 
    141     return {scheme, userinfo, host, port, origin, path, queryString, fragment, lastPathComponent};
     155            result.lastPathComponent = result.path.substring(lastSlashIndex + 1, result.path.length - endOffset);
     156    }
     157
     158    return result;
    142159}
    143160
Note: See TracChangeset for help on using the changeset viewer.