Skip to content

Commit 865cbc8

Browse files
committed
Solidus stripping in DOMURL::setHostname seems wrong
https://bugs.webkit.org/show_bug.cgi?id=127970 Reviewed by Youenn Fablet. Stop stripping solidus from input in URL.hostname setter. This doesn't match the behavior of Blink or Gecko. * LayoutTests/imported/w3c/web-platform-tests/url/url-setters-a-area.window-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/url/url-setters.any-expected.txt: * Source/WebCore/html/URLDecomposition.cpp: (WebCore::URLDecomposition::setHostname): (WebCore::removeAllLeadingSolidusCharacters): Deleted. Canonical link: https://commits.webkit.org/259366@main
1 parent 2b00f86 commit 865cbc8

File tree

8 files changed

+13
-25
lines changed

8 files changed

+13
-25
lines changed

LayoutTests/fast/dom/DOMURL/set-href-attribute-hostname-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
66
Basic test
77
PASS a.href is 'https://www.otherdomain.com:8080/path/'
88
Extra slashes before hostname
9-
PASS a.href is 'https://www.otherdomain.com:8080/path/'
9+
PASS a.href is 'https://www.mydomain.com:8080/path/'
1010
Set hostname to URL with foo: protocol
1111
PASS a.href is 'foo://www.otherdomain.com/path/'
1212
Set hostname to null

LayoutTests/fast/dom/DOMURL/set-href-attribute-hostname.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
debug("Extra slashes before hostname");
2222
a.href = "https://www.mydomain.com:8080/path/";
2323
a.hostname = "//www.otherdomain.com";
24-
shouldBe("a.href", "'https://www.otherdomain.com:8080/path/'");
24+
shouldBe("a.href", "'https://www.mydomain.com:8080/path/'");
2525
} catch(e) {
2626
debug("Exception: " + e.description);
2727
}

LayoutTests/fast/dom/HTMLAnchorElement/set-href-attribute-hostname-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
66
Basic test
77
PASS a.href is 'https://www.otherdomain.com:8080/path/'
88
Extra slashes before hostname
9-
PASS a.href is 'https://www.otherdomain.com:8080/path/'
9+
PASS a.href is 'https://www.mydomain.com:8080/path/'
1010
Set hostname to URL with foo: protocol
1111
PASS a.href is 'foo://www.otherdomain.com/path/'
1212
Set hostname to null

LayoutTests/fast/dom/HTMLAnchorElement/set-href-attribute-hostname.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
debug("Extra slashes before hostname");
2020
a.href = "https://www.mydomain.com:8080/path/";
2121
a.hostname = "//www.otherdomain.com";
22-
shouldBe("a.href", "'https://www.otherdomain.com:8080/path/'");
22+
shouldBe("a.href", "'https://www.mydomain.com:8080/path/'");
2323
} catch(e) {
2424
debug("Exception: " + e.description);
2525
}

LayoutTests/imported/w3c/web-platform-tests/url/url-setters-a-area.window-expected.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,10 @@ PASS <a>: Setting <non-spec:/.//p>.hostname = 'h' Drop /. from path
292292
PASS <area>: Setting <non-spec:/.//p>.hostname = 'h' Drop /. from path
293293
PASS <a>: Setting <non-spec:/.//p>.hostname = ''
294294
PASS <area>: Setting <non-spec:/.//p>.hostname = ''
295-
FAIL <a>: Setting <http://example.com/>.hostname = '///bad.com' Leading / is not stripped assert_equals: expected "http://example.com/" but got "http://bad.com/"
296-
FAIL <area>: Setting <http://example.com/>.hostname = '///bad.com' Leading / is not stripped assert_equals: expected "http://example.com/" but got "http://bad.com/"
297-
FAIL <a>: Setting <sc://example.com/>.hostname = '///bad.com' Leading / is not stripped assert_equals: expected "sc:///" but got "sc://bad.com/"
298-
FAIL <area>: Setting <sc://example.com/>.hostname = '///bad.com' Leading / is not stripped assert_equals: expected "sc:///" but got "sc://bad.com/"
295+
PASS <a>: Setting <http://example.com/>.hostname = '///bad.com' Leading / is not stripped
296+
PASS <area>: Setting <http://example.com/>.hostname = '///bad.com' Leading / is not stripped
297+
PASS <a>: Setting <sc://example.com/>.hostname = '///bad.com' Leading / is not stripped
298+
PASS <area>: Setting <sc://example.com/>.hostname = '///bad.com' Leading / is not stripped
299299
PASS <a>: Setting <http://example.net>.port = '8080'
300300
PASS <area>: Setting <http://example.net>.port = '8080'
301301
PASS <a>: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value

LayoutTests/imported/w3c/web-platform-tests/url/url-setters.any-expected.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ PASS URL: Setting <sc://test@test/>.hostname = ''
146146
PASS URL: Setting <sc://test:12/>.hostname = ''
147147
PASS URL: Setting <non-spec:/.//p>.hostname = 'h' Drop /. from path
148148
PASS URL: Setting <non-spec:/.//p>.hostname = ''
149-
FAIL URL: Setting <http://example.com/>.hostname = '///bad.com' Leading / is not stripped assert_equals: expected "http://example.com/" but got "http://bad.com/"
150-
FAIL URL: Setting <sc://example.com/>.hostname = '///bad.com' Leading / is not stripped assert_equals: expected "sc:///" but got "sc://bad.com/"
149+
PASS URL: Setting <http://example.com/>.hostname = '///bad.com' Leading / is not stripped
150+
PASS URL: Setting <sc://example.com/>.hostname = '///bad.com' Leading / is not stripped
151151
PASS URL: Setting <http://example.net>.port = '8080'
152152
PASS URL: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value
153153
PASS URL: Setting <http://example.net:8080>.port = '80' Default port number is removed

LayoutTests/imported/w3c/web-platform-tests/url/url-setters.any.worker-expected.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ PASS URL: Setting <sc://test@test/>.hostname = ''
146146
PASS URL: Setting <sc://test:12/>.hostname = ''
147147
PASS URL: Setting <non-spec:/.//p>.hostname = 'h' Drop /. from path
148148
PASS URL: Setting <non-spec:/.//p>.hostname = ''
149-
FAIL URL: Setting <http://example.com/>.hostname = '///bad.com' Leading / is not stripped assert_equals: expected "http://example.com/" but got "http://bad.com/"
150-
FAIL URL: Setting <sc://example.com/>.hostname = '///bad.com' Leading / is not stripped assert_equals: expected "sc:///" but got "sc://bad.com/"
149+
PASS URL: Setting <http://example.com/>.hostname = '///bad.com' Leading / is not stripped
150+
PASS URL: Setting <sc://example.com/>.hostname = '///bad.com' Leading / is not stripped
151151
PASS URL: Setting <http://example.net>.port = '8080'
152152
PASS URL: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value
153153
PASS URL: Setting <http://example.net:8080>.port = '80' Default port number is removed

Source/WebCore/html/URLDecomposition.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,9 @@ String URLDecomposition::hostname() const
135135
return fullURL().host().toString();
136136
}
137137

138-
static StringView removeAllLeadingSolidusCharacters(StringView string)
139-
{
140-
unsigned i;
141-
unsigned length = string.length();
142-
for (i = 0; i < length; ++i) {
143-
if (string[i] != '/')
144-
break;
145-
}
146-
return string.substring(i);
147-
}
148-
149-
void URLDecomposition::setHostname(StringView value)
138+
void URLDecomposition::setHostname(StringView host)
150139
{
151140
auto fullURL = this->fullURL();
152-
auto host = removeAllLeadingSolidusCharacters(value);
153141
if (host.isEmpty() && !fullURL.protocolIs("file"_s) && fullURL.hasSpecialScheme())
154142
return;
155143
if (fullURL.cannotBeABaseURL() || !fullURL.canSetHostOrPort())

0 commit comments

Comments
 (0)