Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use non-symbols in isURLInstance check #24862

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions patches/node/.patches
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ win_use_rtlgenrandom_from_advapi32_dll_directly.patch
tools_update_certdata_txt.patch
crypto_update_root_certificates.patch
darwin_work_around_clock_jumping_back_in_time.patch
lib_use_non-symbols_in_isurlinstance_check.patch
39 changes: 39 additions & 0 deletions patches/node/lib_use_non-symbols_in_isurlinstance_check.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
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 860fa4d7ad01b391d7d8e4c5ffe432d4d1d5983e..7d557a51930b7f225d128425fcc9db959c13392c 100644
--- a/lib/internal/url.js
+++ b/lib/internal/url.js
@@ -1334,8 +1334,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');
@@ -1383,8 +1382,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);
}
9 changes: 9 additions & 0 deletions spec/node-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,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');
Expand Down