From e81593e40ff87bcb11a18305f21e2e9d0279f2e3 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 4 Aug 2020 09:18:43 -0700 Subject: [PATCH 1/5] fix: use non-symbols in isURLInstance check --- patches/node/.patches | 1 + ...e_non-symbols_in_isurlinstance_check.patch | 40 +++++++++++++++++++ spec/node-spec.js | 9 +++++ 3 files changed, 50 insertions(+) create mode 100644 patches/node/lib_use_non-symbols_in_isurlinstance_check.patch diff --git a/patches/node/.patches b/patches/node/.patches index 70ce8c1dd15c1..838938ed07d05 100644 --- a/patches/node/.patches +++ b/patches/node/.patches @@ -51,3 +51,4 @@ crypto_update_root_certificates_to_nss_3_47.patch tools_update_certdata_txt_to_nss_3_53.patch crypto_update_root_certificates_to_nss_3_53.patch darwin_work_around_clock_jumping_back_in_time.patch +lib_use_non-symbols_in_isurlinstance_check.patch diff --git a/patches/node/lib_use_non-symbols_in_isurlinstance_check.patch b/patches/node/lib_use_non-symbols_in_isurlinstance_check.patch new file mode 100644 index 0000000000000..73d8adbbdb943 --- /dev/null +++ b/patches/node/lib_use_non-symbols_in_isurlinstance_check.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Shelley Vohr +Date: Tue, 4 Aug 2020 09:17:06 -0700 +Subject: lib: use non-symbols in isURLInstance check + +This slightly changes the conditional used to determine whether or +not something is a URL instance. Since Node.js adds symbols to the URL +not specified by the WHATWG, those symbols are not present in other +implementations (like Blink's) and therefore can cause false negatives. + +This fixes that by slightly changing the check to properties present +in all URL instances as specified in the WHATWG spec. + +Upstreamed at: https://github.com/nodejs/node/pull/34622. + +diff --git a/lib/internal/url.js b/lib/internal/url.js +index 09fa9f2cf47d50d369fa3eae378f81767486e83e..e6a37dcd22c51b37838a577be44be198649eabad 100644 +--- a/lib/internal/url.js ++++ b/lib/internal/url.js +@@ -1348,8 +1348,7 @@ function getPathFromURLPosix(url) { + function fileURLToPath(path) { + if (typeof path === 'string') + path = new URL(path); +- else if (path == null || !path[searchParams] || +- !path[searchParams][searchParams]) ++ else if (path == null || !path['origin'] || !path['href']) + throw new ERR_INVALID_ARG_TYPE('path', ['string', 'URL'], path); + if (path.protocol !== 'file:') + throw new ERR_INVALID_URL_SCHEME('file'); +@@ -1397,8 +1396,7 @@ function pathToFileURL(filepath) { + } + + function toPathIfFileURL(fileURLOrPath) { +- if (fileURLOrPath == null || !fileURLOrPath[searchParams] || +- !fileURLOrPath[searchParams][searchParams]) ++ if (fileURLOrPath == null || !fileURLOrPath['origin'] || !fileURLOrPath['href']) + return fileURLOrPath; + return fileURLToPath(fileURLOrPath); + } + \ No newline at end of file diff --git a/spec/node-spec.js b/spec/node-spec.js index ab9e180d31238..75516b449ef85 100644 --- a/spec/node-spec.js +++ b/spec/node-spec.js @@ -191,6 +191,15 @@ describe('node feature', () => { }); }); + describe('URL handling in the renderer process', () => { + it('can successfully handle WHATWG URLs constructed by Blink', () => { + const url = new URL('file://' + path.resolve(fixtures, 'pages', 'base-page.html')); + expect(() => { + fs.createReadStream(url); + }).to.not.throw(); + }); + }); + describe('error thrown in main process node context', () => { it('gets emitted as a process uncaughtException event', () => { const error = ipcRenderer.sendSync('handle-uncaught-exception', 'hello'); From 1e15c4081eeb2173487ac1bd92c243d1dc8386e2 Mon Sep 17 00:00:00 2001 From: Electron Bot Date: Thu, 6 Aug 2020 17:21:08 +0000 Subject: [PATCH 2/5] update patches --- .../node/lib_use_non-symbols_in_isurlinstance_check.patch | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/patches/node/lib_use_non-symbols_in_isurlinstance_check.patch b/patches/node/lib_use_non-symbols_in_isurlinstance_check.patch index 73d8adbbdb943..c8652fae0dcee 100644 --- a/patches/node/lib_use_non-symbols_in_isurlinstance_check.patch +++ b/patches/node/lib_use_non-symbols_in_isurlinstance_check.patch @@ -14,10 +14,10 @@ in all URL instances as specified in the WHATWG spec. Upstreamed at: https://github.com/nodejs/node/pull/34622. diff --git a/lib/internal/url.js b/lib/internal/url.js -index 09fa9f2cf47d50d369fa3eae378f81767486e83e..e6a37dcd22c51b37838a577be44be198649eabad 100644 +index fde643bea370c86d8a7e7f17ae8aa12894028abf..a39ba02d6f4cfaa1ca2325366cd52f50b8dbfbe7 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js -@@ -1348,8 +1348,7 @@ function getPathFromURLPosix(url) { +@@ -1334,8 +1334,7 @@ function getPathFromURLPosix(url) { function fileURLToPath(path) { if (typeof path === 'string') path = new URL(path); @@ -27,7 +27,7 @@ index 09fa9f2cf47d50d369fa3eae378f81767486e83e..e6a37dcd22c51b37838a577be44be198 throw new ERR_INVALID_ARG_TYPE('path', ['string', 'URL'], path); if (path.protocol !== 'file:') throw new ERR_INVALID_URL_SCHEME('file'); -@@ -1397,8 +1396,7 @@ function pathToFileURL(filepath) { +@@ -1383,8 +1382,7 @@ function pathToFileURL(filepath) { } function toPathIfFileURL(fileURLOrPath) { @@ -37,4 +37,3 @@ index 09fa9f2cf47d50d369fa3eae378f81767486e83e..e6a37dcd22c51b37838a577be44be198 return fileURLOrPath; return fileURLToPath(fileURLOrPath); } - \ No newline at end of file From 1f3b1157b45ef389947450196f0d29acf110bed0 Mon Sep 17 00:00:00 2001 From: Electron Bot Date: Thu, 6 Aug 2020 17:42:53 +0000 Subject: [PATCH 3/5] update patches From 3eb1275e066f555e8983fcd9d61bdc0aa0d236e9 Mon Sep 17 00:00:00 2001 From: Electron Bot Date: Thu, 6 Aug 2020 18:00:58 +0000 Subject: [PATCH 4/5] update patches From 30b2d1e635f53fed9aacf55c1a95eac42b20bd8b Mon Sep 17 00:00:00 2001 From: Electron Bot Date: Fri, 7 Aug 2020 04:01:32 +0000 Subject: [PATCH 5/5] update patches --- patches/node/lib_use_non-symbols_in_isurlinstance_check.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patches/node/lib_use_non-symbols_in_isurlinstance_check.patch b/patches/node/lib_use_non-symbols_in_isurlinstance_check.patch index c8652fae0dcee..fb65736f9fe4b 100644 --- a/patches/node/lib_use_non-symbols_in_isurlinstance_check.patch +++ b/patches/node/lib_use_non-symbols_in_isurlinstance_check.patch @@ -29,7 +29,7 @@ index fde643bea370c86d8a7e7f17ae8aa12894028abf..a39ba02d6f4cfaa1ca2325366cd52f50 throw new ERR_INVALID_URL_SCHEME('file'); @@ -1383,8 +1382,7 @@ function pathToFileURL(filepath) { } - + function toPathIfFileURL(fileURLOrPath) { - if (fileURLOrPath == null || !fileURLOrPath[searchParams] || - !fileURLOrPath[searchParams][searchParams])