Commit 2f4b4ffa authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

An empty string to URL.prototype.port sets the port to null

KURL::SetPort("") will yield a port of "0", use ḰURL::RemovePort instead
which does the equivalent of what the spec says:

  "2. If the given value is the empty string, then set context object’s
      url’s port to null."

  https://url.spec.whatwg.org/#dom-url-port

Bug: 971684
Change-Id: I68b218f5e7a596a54944be05a51a32fd93fbf677
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1658153Reviewed-by: default avatarMike West <mkwst@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#670027}
parent 40935da5
......@@ -97,8 +97,10 @@ void DOMURLUtils::setPort(const String& value) {
KURL kurl = Url();
if (!kurl.CanSetHostOrPort())
return;
kurl.SetPort(value);
if (!value.IsEmpty())
kurl.SetPort(value);
else
kurl.RemovePort();
SetURL(kurl);
}
......
......@@ -13,7 +13,7 @@ PASS a.href is 'https://www.mydomain.com:4/path/testurl.html?key=value'
Set port to null
PASS a.href is 'https://www.mydomain.com:0/path/testurl.html?key=value'
Set port to empty string
PASS a.href is 'https://www.mydomain.com:0/path/testurl.html?key=value'
PASS a.href is 'https://www.mydomain.com/path/testurl.html?key=value'
Set port to undefined
PASS a.href is 'https://www.mydomain.com:0/path/testurl.html?key=value'
Set port to URL with foo: protocol
......
......@@ -40,7 +40,7 @@ shouldBe("a.href", "'https://www.mydomain.com:0/path/testurl.html?key=value'");
debug("Set port to empty string");
a.href = "https://www.mydomain.com:8080/path/testurl.html?key=value";
a.port = "";
shouldBe("a.href", "'https://www.mydomain.com:0/path/testurl.html?key=value'");
shouldBe("a.href", "'https://www.mydomain.com/path/testurl.html?key=value'");
debug("Set port to undefined");
a.href = "https://www.mydomain.com:8080/path/testurl.html?key=value";
......
......@@ -15,7 +15,7 @@ test(function() {
assert_equals(url.port, '8081');
url.port = '';
assert_equals(url.port, '0');
assert_equals(url.port, '');
url.port = 80;
assert_equals(url.port, '');
......
This is a testharness.js-based test.
Found 592 tests; 296 PASS, 296 FAIL, 0 TIMEOUT, 0 NOTRUN.
Found 592 tests; 299 PASS, 293 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS Loading data…
PASS URL: Setting <a://example.net>.protocol = '' The empty string is not a valid scheme. Setter leaves the URL unchanged.
PASS <a>: Setting <a://example.net>.protocol = '' The empty string is not a valid scheme. Setter leaves the URL unchanged.
......@@ -427,9 +427,9 @@ FAIL <area>: Setting <sc://test:12/>.hostname = '' assert_equals: expected "test
PASS URL: Setting <http://example.net>.port = '8080'
PASS <a>: Setting <http://example.net>.port = '8080'
PASS <area>: Setting <http://example.net>.port = '8080'
FAIL URL: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value assert_equals: expected "http://example.net/" but got "http://example.net:0/"
FAIL <a>: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value assert_equals: expected "http://example.net/" but got "http://example.net:0/"
FAIL <area>: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value assert_equals: expected "http://example.net/" but got "http://example.net:0/"
PASS URL: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value
PASS <a>: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value
PASS <area>: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value
PASS URL: Setting <http://example.net:8080>.port = '80' Default port number is removed
PASS <a>: Setting <http://example.net:8080>.port = '80' Default port number is removed
PASS <area>: Setting <http://example.net:8080>.port = '80' Default port number is removed
......
This is a testharness.js-based test.
Found 592 tests; 296 PASS, 296 FAIL, 0 TIMEOUT, 0 NOTRUN.
Found 592 tests; 299 PASS, 293 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS Loading data…
PASS URL: Setting <a://example.net>.protocol = '' The empty string is not a valid scheme. Setter leaves the URL unchanged.
PASS <a>: Setting <a://example.net>.protocol = '' The empty string is not a valid scheme. Setter leaves the URL unchanged.
......@@ -427,9 +427,9 @@ FAIL <area>: Setting <sc://test:12/>.hostname = '' assert_equals: expected "test
PASS URL: Setting <http://example.net>.port = '8080'
PASS <a>: Setting <http://example.net>.port = '8080'
PASS <area>: Setting <http://example.net>.port = '8080'
FAIL URL: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value assert_equals: expected "http://example.net/" but got "http://example.net:0/"
FAIL <a>: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value assert_equals: expected "http://example.net/" but got "http://example.net:0/"
FAIL <area>: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value assert_equals: expected "http://example.net/" but got "http://example.net:0/"
PASS URL: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value
PASS <a>: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value
PASS <area>: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value
PASS URL: Setting <http://example.net:8080>.port = '80' Default port number is removed
PASS <a>: Setting <http://example.net:8080>.port = '80' Default port number is removed
PASS <area>: Setting <http://example.net:8080>.port = '80' Default port number is removed
......
This is a testharness.js-based test.
Found 592 tests; 269 PASS, 323 FAIL, 0 TIMEOUT, 0 NOTRUN.
Found 592 tests; 272 PASS, 320 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS Loading data…
FAIL URL: Setting <a://example.net>.protocol = '' The empty string is not a valid scheme. Setter leaves the URL unchanged. assert_equals: expected "a://example.net" but got "file:///A://example.net"
FAIL <a>: Setting <a://example.net>.protocol = '' The empty string is not a valid scheme. Setter leaves the URL unchanged. assert_equals: expected "a://example.net" but got "file:///A://example.net"
......@@ -427,9 +427,9 @@ FAIL <area>: Setting <sc://test:12/>.hostname = '' assert_equals: expected "test
PASS URL: Setting <http://example.net>.port = '8080'
PASS <a>: Setting <http://example.net>.port = '8080'
PASS <area>: Setting <http://example.net>.port = '8080'
FAIL URL: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value assert_equals: expected "http://example.net/" but got "http://example.net:0/"
FAIL <a>: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value assert_equals: expected "http://example.net/" but got "http://example.net:0/"
FAIL <area>: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value assert_equals: expected "http://example.net/" but got "http://example.net:0/"
PASS URL: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value
PASS <a>: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value
PASS <area>: Setting <http://example.net:8080>.port = '' Port number is removed if empty is the new value
PASS URL: Setting <http://example.net:8080>.port = '80' Default port number is removed
PASS <a>: Setting <http://example.net:8080>.port = '80' Default port number is removed
PASS <area>: Setting <http://example.net:8080>.port = '80' Default port number is removed
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment