forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WebSocket: Allow relative URLs and http(s) scheme
https://bugs.webkit.org/show_bug.cgi?id=247149 rdar://101929623 Reviewed by Antti Koivisto. This implements the change proposed at whatwg/websockets#45, allowing HTTP(S) URLs to be used in the WebSocket constructor. They are immediately converted to use ws: or wss: schemes. It also ensures that the HTTP(S) URLs always use UTF-8 for the query component of the URL, as is expected. The test changes are being upstreamed via web-platform-tests/wpt#39955. * LayoutTests/TestExpectations: * LayoutTests/http/tests/websocket/tests/hybi/url-parsing-expected.txt: * LayoutTests/http/tests/websocket/tests/hybi/url-parsing.html: * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-http-urls.any-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-http-urls.any.html: Added. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-http-urls.any.js: Added. (test): * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-http-urls.any.worker-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-http-urls.any.worker.html: Added. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-invalid-urls.any-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-invalid-urls.any.html: * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-invalid-urls.any.js: (string_appeared_here.forEach.input.test): (test): Deleted. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-invalid-urls.any.worker-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-invalid-urls.any.worker.html: * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-invalid-urls.any.worker_wss-expected.txt: Removed. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-invalid-urls.any_wss-expected.txt: Removed. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-non-absolute-url.any-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-non-absolute-url.any.html: * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-non-absolute-url.any.js: (forEach.input.test): (test): Deleted. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-non-absolute-url.any.worker-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-non-absolute-url.any.worker.html: * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-non-absolute-url.any.worker_wss-expected.txt: Removed. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-non-absolute-url.any_wss-expected.txt: Removed. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-url-with-windows-1252-encoding-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-url-with-windows-1252-encoding.html: Added. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-wrong-scheme.any.html: Removed. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-wrong-scheme.any.js: Removed. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-wrong-scheme.any.worker.html: Removed. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-wrong-scheme.any.worker_wss-expected.txt: Removed. * LayoutTests/imported/w3c/web-platform-tests/websockets/Create-wrong-scheme.any_wss-expected.txt: Removed. * LayoutTests/imported/w3c/web-platform-tests/websockets/constants.sub.js: (CreateWebSocketNonAbsolute): Deleted. (CreateWebSocketNonWsScheme): Deleted. * LayoutTests/imported/w3c/web-platform-tests/websockets/constructor/002-expected.txt: Removed. * LayoutTests/imported/w3c/web-platform-tests/websockets/constructor/002.html: Removed. * LayoutTests/imported/w3c/web-platform-tests/websockets/constructor/002_wss-expected.txt: Removed. * LayoutTests/imported/w3c/web-platform-tests/websockets/constructor/w3c-import.log: * LayoutTests/imported/w3c/web-platform-tests/websockets/w3c-import.log: * LayoutTests/platform/glib/TestExpectations: * Source/WebCore/Modules/websockets/WebSocket.cpp: (WebCore::WebSocket::create): (WebCore::WebSocket::connect): Canonical link: https://commits.webkit.org/263968@main
- Loading branch information
Showing
37 changed files
with
141 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
LayoutTests/imported/w3c/web-platform-tests/websockets/Create-http-urls.any-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
PASS WebSocket: ensure both HTTP schemes are supported | ||
|
1 change: 1 addition & 0 deletions
1
LayoutTests/imported/w3c/web-platform-tests/websockets/Create-http-urls.any.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!-- This file is required for WebKit test infrastructure to run the templated test --> |
19 changes: 19 additions & 0 deletions
19
LayoutTests/imported/w3c/web-platform-tests/websockets/Create-http-urls.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
test(() => { | ||
const url = new URL ("/", location); | ||
url.protocol = "http"; | ||
const httpURL = url.href; | ||
url.protocol = "https"; | ||
const httpsURL = url.href; | ||
url.protocol = "ws"; | ||
const wsURL = url.href; | ||
url.protocol = "wss"; | ||
const wssURL = url.href; | ||
|
||
let ws = new WebSocket(httpURL); | ||
assert_equals(ws.url, wsURL); | ||
ws.close(); | ||
|
||
ws = new WebSocket(httpsURL); | ||
assert_equals(ws.url, wssURL); | ||
ws.close(); | ||
}, "WebSocket: ensure both HTTP schemes are supported"); |
3 changes: 3 additions & 0 deletions
3
...Tests/imported/w3c/web-platform-tests/websockets/Create-http-urls.any.worker-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
PASS WebSocket: ensure both HTTP schemes are supported | ||
|
1 change: 1 addition & 0 deletions
1
LayoutTests/imported/w3c/web-platform-tests/websockets/Create-http-urls.any.worker.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!-- This file is required for WebKit test infrastructure to run the templated test --> |
10 changes: 10 additions & 0 deletions
10
LayoutTests/imported/w3c/web-platform-tests/websockets/Create-invalid-urls.any-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
PASS new WebSocket("ws://foo bar.com/") should throw a "SyntaxError" DOMException | ||
PASS new WebSocket("wss://foo bar.com/") should throw a "SyntaxError" DOMException | ||
PASS new WebSocket("ftp://localhost:8800/") should throw a "SyntaxError" DOMException | ||
PASS new WebSocket("mailto:example@example.org") should throw a "SyntaxError" DOMException | ||
PASS new WebSocket("about:blank") should throw a "SyntaxError" DOMException | ||
PASS new WebSocket("http://localhost:8800/#") should throw a "SyntaxError" DOMException | ||
PASS new WebSocket("http://localhost:8800/#test") should throw a "SyntaxError" DOMException | ||
PASS new WebSocket("#test") should throw a "SyntaxError" DOMException | ||
|
5 changes: 1 addition & 4 deletions
5
LayoutTests/imported/w3c/web-platform-tests/websockets/Create-invalid-urls.any.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
<!-- This file is required for WebKit test infrastructure to run the templated test --> | ||
<!-- META: variant= --> | ||
<!-- META: variant=?wss --> | ||
<!-- META: variant=?wpt_flags=h2 --> | ||
<!-- This file is required for WebKit test infrastructure to run the templated test --> |
48 changes: 14 additions & 34 deletions
48
LayoutTests/imported/w3c/web-platform-tests/websockets/Create-invalid-urls.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,14 @@ | ||
// META: variant= | ||
// META: variant=?wss | ||
// META: variant=?wpt_flags=h2 | ||
|
||
var wsocket; | ||
test(function() { | ||
assert_throws_dom("SYNTAX_ERR", function() { | ||
wsocket = new WebSocket("/echo") | ||
}); | ||
}, "Url is /echo - should throw SYNTAX_ERR"); | ||
|
||
test(function() { | ||
assert_throws_dom("SYNTAX_ERR", function() { | ||
wsocket = new WebSocket("mailto:microsoft@microsoft.com") | ||
}); | ||
}, "Url is a mail address - should throw SYNTAX_ERR"); | ||
|
||
test(function() { | ||
assert_throws_dom("SYNTAX_ERR", function() { | ||
wsocket = new WebSocket("about:blank") | ||
}); | ||
}, "Url is about:blank - should throw SYNTAX_ERR"); | ||
|
||
test(function() { | ||
assert_throws_dom("SYNTAX_ERR", function() { | ||
wsocket = new WebSocket("?test") | ||
}); | ||
}, "Url is ?test - should throw SYNTAX_ERR"); | ||
|
||
test(function() { | ||
assert_throws_dom("SYNTAX_ERR", function() { | ||
wsocket = new WebSocket("#test") | ||
}); | ||
}, "Url is #test - should throw SYNTAX_ERR"); | ||
[ | ||
"ws://foo bar.com/", | ||
"wss://foo bar.com/", | ||
"ftp://"+location.host+"/", | ||
"mailto:example@example.org", | ||
"about:blank", | ||
location.origin + "/#", | ||
location.origin + "/#test", | ||
"#test" | ||
].forEach(input => { | ||
test(() => { | ||
assert_throws_dom("SyntaxError", () => new WebSocket(input)); | ||
}, `new WebSocket("${input}") should throw a "SyntaxError" DOMException`); | ||
}); |
10 changes: 10 additions & 0 deletions
10
...ts/imported/w3c/web-platform-tests/websockets/Create-invalid-urls.any.worker-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
PASS new WebSocket("ws://foo bar.com/") should throw a "SyntaxError" DOMException | ||
PASS new WebSocket("wss://foo bar.com/") should throw a "SyntaxError" DOMException | ||
PASS new WebSocket("ftp://localhost:8800/") should throw a "SyntaxError" DOMException | ||
PASS new WebSocket("mailto:example@example.org") should throw a "SyntaxError" DOMException | ||
PASS new WebSocket("about:blank") should throw a "SyntaxError" DOMException | ||
PASS new WebSocket("http://localhost:8800/#") should throw a "SyntaxError" DOMException | ||
PASS new WebSocket("http://localhost:8800/#test") should throw a "SyntaxError" DOMException | ||
PASS new WebSocket("#test") should throw a "SyntaxError" DOMException | ||
|
5 changes: 1 addition & 4 deletions
5
LayoutTests/imported/w3c/web-platform-tests/websockets/Create-invalid-urls.any.worker.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
<!-- This file is required for WebKit test infrastructure to run the templated test --> | ||
<!-- META: variant= --> | ||
<!-- META: variant=?wss --> | ||
<!-- META: variant=?wpt_flags=h2 --> | ||
<!-- This file is required for WebKit test infrastructure to run the templated test --> |
7 changes: 0 additions & 7 deletions
7
...mported/w3c/web-platform-tests/websockets/Create-invalid-urls.any.worker_wss-expected.txt
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
...Tests/imported/w3c/web-platform-tests/websockets/Create-invalid-urls.any_wss-expected.txt
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
...Tests/imported/w3c/web-platform-tests/websockets/Create-non-absolute-url.any-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
PASS Create WebSocket - Pass a non absolute URL: test | ||
PASS Create WebSocket - Pass a non absolute URL: ? | ||
PASS Create WebSocket - Pass a non absolute URL: null | ||
PASS Create WebSocket - Pass a non absolute URL: 123 | ||
|
5 changes: 1 addition & 4 deletions
5
LayoutTests/imported/w3c/web-platform-tests/websockets/Create-non-absolute-url.any.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
<!-- This file is required for WebKit test infrastructure to run the templated test --> | ||
<!-- META: variant= --> | ||
<!-- META: variant=?wss --> | ||
<!-- META: variant=?wpt_flags=h2 --> | ||
<!-- This file is required for WebKit test infrastructure to run the templated test --> |
25 changes: 14 additions & 11 deletions
25
LayoutTests/imported/w3c/web-platform-tests/websockets/Create-non-absolute-url.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
// META: script=constants.sub.js | ||
// META: variant= | ||
// META: variant=?wss | ||
// META: variant=?wpt_flags=h2 | ||
|
||
test(function() { | ||
var wsocket; | ||
assert_throws_dom("SYNTAX_ERR", function() { | ||
wsocket = CreateWebSocketNonAbsolute() | ||
}); | ||
}, "Create WebSocket - Pass a non absolute URL - SYNTAX_ERR is thrown") | ||
[ | ||
"test", | ||
"?", | ||
null, | ||
123, | ||
].forEach(input => { | ||
test(() => { | ||
const url = new URL(input, location); | ||
url.protocol = "ws"; | ||
const ws = new WebSocket(input); | ||
assert_equals(ws.url, url.href); | ||
ws.close(); | ||
}, `Create WebSocket - Pass a non absolute URL: ${input}`); | ||
}); |
6 changes: 6 additions & 0 deletions
6
...mported/w3c/web-platform-tests/websockets/Create-non-absolute-url.any.worker-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
PASS Create WebSocket - Pass a non absolute URL: test | ||
PASS Create WebSocket - Pass a non absolute URL: ? | ||
PASS Create WebSocket - Pass a non absolute URL: null | ||
PASS Create WebSocket - Pass a non absolute URL: 123 | ||
|
5 changes: 1 addition & 4 deletions
5
...tTests/imported/w3c/web-platform-tests/websockets/Create-non-absolute-url.any.worker.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
<!-- This file is required for WebKit test infrastructure to run the templated test --> | ||
<!-- META: variant= --> | ||
<!-- META: variant=?wss --> | ||
<!-- META: variant=?wpt_flags=h2 --> | ||
<!-- This file is required for WebKit test infrastructure to run the templated test --> |
3 changes: 0 additions & 3 deletions
3
...ted/w3c/web-platform-tests/websockets/Create-non-absolute-url.any.worker_wss-expected.txt
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
...s/imported/w3c/web-platform-tests/websockets/Create-non-absolute-url.any_wss-expected.txt
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...rted/w3c/web-platform-tests/websockets/Create-url-with-windows-1252-encoding-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
PASS URL's percent-encoding is always in UTF-8 for WebSocket | ||
|
20 changes: 20 additions & 0 deletions
20
...sts/imported/w3c/web-platform-tests/websockets/Create-url-with-windows-1252-encoding.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!doctype html> | ||
<meta charset=windows-1252> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script> | ||
test(() => { | ||
const url = new URL("/", location); | ||
url.protocol = "ws"; | ||
const input = "?\u20AC"; | ||
const expected = url.href + "?%E2%82%AC"; | ||
|
||
let ws = new WebSocket(url.href + input); | ||
assert_equals(ws.url, expected); | ||
ws.close(); | ||
|
||
ws = new WebSocket("/" + input); | ||
assert_equals(ws.url, expected); | ||
ws.close(); | ||
}, "URL's percent-encoding is always in UTF-8 for WebSocket"); | ||
</script> |
4 changes: 0 additions & 4 deletions
4
LayoutTests/imported/w3c/web-platform-tests/websockets/Create-wrong-scheme.any.html
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
LayoutTests/imported/w3c/web-platform-tests/websockets/Create-wrong-scheme.any.js
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
LayoutTests/imported/w3c/web-platform-tests/websockets/Create-wrong-scheme.any.worker.html
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
...mported/w3c/web-platform-tests/websockets/Create-wrong-scheme.any.worker_wss-expected.txt
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
...Tests/imported/w3c/web-platform-tests/websockets/Create-wrong-scheme.any_wss-expected.txt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
LayoutTests/imported/w3c/web-platform-tests/websockets/constructor/002-expected.txt
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
LayoutTests/imported/w3c/web-platform-tests/websockets/constructor/002.html
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
LayoutTests/imported/w3c/web-platform-tests/websockets/constructor/002_wss-expected.txt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.