Fix a regression on non-special URL, like "git:\opaque\path"
Chrome M130 supports non-special URL, however, a regression is reported
at http://crbug.com/373928202.
The summary is:
Chrome <= 129:
| No | URL | valid url? | url.hostname | url.path |
|----+------------------+------------+--------------+----------------|
| 1 | TEST://PC/FOLDER | valid | "" | "//PC/FOLDER" |
| 2 | TEST://PC\FOLDER | valid | "" | "//PC\FOLDER" |
| 3 | TEST:\PC\FOLDER | valid | "" | "\PC\FOLDER" |
| 4 | TEST:\PC | valid | "" | "\PC" |
Chrome 130:
| No | URL | valid url? | url.hostname | url.path |
|----+------------------+------------+--------------+---------------|
| 1 | TEST://PC/FOLDER | valid | "pc" | "/FOLDEDR" |
| 2 | TEST://PC\FOLDER | invalid | - | - |
| 3 | TEST:\PC\FOLDER | invalid | - | - |
| 4 | TEST:\PC | valid | "pc" | "" |
URL Standard (expected behaviors)
| No | URL | valid url? | url.hostname | url.path |
|----+------------------+------------+--------------+---------------|
| 1 | TEST://PC/FOLDER | valid | "pc" | "/FOLDEDR" |
| 2 | TEST://PC\FOLDER | invalid | - | - |
| 3 | TEST:\PC\FOLDER | valid | "" | "\PC\FOLDER" |
| 4 | TEST:\PC | valid | "" | "\PC" |
The problems is URL No.3 or No4, where "\" (two backslashes) follows
after "scheme:", for which Chrome M130 is not spec-compliant.
These URLs should be a valid opaque path URL, however, Chrome M130
treat them wrongly.
The reason:
The current (wrong) URL parser counts backslahses as well as slashes
after "scheme:". This behavior is the correct behavior for a special
URL, like "https:\PC\FOLDER", but NOT for non-special URLs, like
"TEST:\PC\FOLDER", unfortunately.
For your reference, the URL Standard says that at the following place:
https://url.spec.whatwg.org/#scheme-state
- Otherwise, if url is special, set state to special authority
slashes state.- Otherwise, if remaining starts with an U+002F (/), set state to
path or authority state and increase pointer by 1.- Otherwise, set url’s path to the empty string and set state to
opaque path state.
It's a bit cryptic, but if you read this part (and other parts too)
carefully, it says so. :(
Unfortunately, the current WPT doesn't cover these test cases, so we
didn't notice this regression.
This CL fixes a regression by implement that URL standard part, and
also add WPT tests to prevent a regression.
Bug: 40063064,373928202
Change-Id: Ia5ba5ff16426893c735775c62b7044842d16b46d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5939018
Reviewed-by: Adam Rice ricea@chromium.org
Commit-Queue: Hayato Ito hayato@chromium.org
Cr-Commit-Position: refs/heads/main@{#1370488}