From 6a34b85b05d61d016a1ca5072c94f6b449ab0e06 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`. PR-URL: https://github.com/nodejs/node/pull/26941 Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater Reviewed-By: Yongsheng Zhang --- 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 edc55c87aaaec7..fba5558edb07ea 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 d802b0f6dcc3f6..43c459d936fe61 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/' } };