From 20fb558907eb6568b1b45bb9bdda3be53127f7e3 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Wed, 27 Mar 2019 08:53:15 +0100 Subject: [PATCH] url: add ws: and wss: to slashedProtocol set Fix cases where the pathname is incorrectly parsed as `null`. --- lib/url.js | 6 +++++- test/parallel/test-url-parse-format.js | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/url.js b/lib/url.js index ade0007171ee48..a51e98ceb82a21 100644 --- a/lib/url.js +++ b/lib/url.js @@ -95,7 +95,11 @@ const slashedProtocol = new SafeSet([ 'gopher', 'gopher:', 'file', - 'file:' + 'file:', + 'ws', + 'ws:', + 'wss', + 'wss:' ]); const { CHAR_SPACE, diff --git a/test/parallel/test-url-parse-format.js b/test/parallel/test-url-parse-format.js index b318658febbaea..6d50be0e8b7c63 100644 --- a/test/parallel/test-url-parse-format.js +++ b/test/parallel/test-url-parse-format.js @@ -923,6 +923,26 @@ const parseTests = { pathname: "alert(1);a='@white-listed.com'", path: "alert(1);a='@white-listed.com'", href: "javascript:alert(1);a='@white-listed.com'" + }, + + 'ws://www.example.com': { + protocol: 'ws:', + slashes: true, + hostname: 'www.example.com', + host: 'www.example.com', + pathname: '/', + path: '/', + href: 'ws://www.example.com/' + }, + + 'wss://www.example.com': { + protocol: 'wss:', + slashes: true, + hostname: 'www.example.com', + host: 'www.example.com', + pathname: '/', + path: '/', + href: 'wss://www.example.com/' } };