Skip to content

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. In Electron's renderer process, running e.g. this code:

const fs = require('fs');
const path = require('path');

const url = new URL('file://' + path.resolve('index.html'));

const stream = fs.createReadStream(url);

stream.pipe(process.stdout);

would cause the following error:

"Uncaught TypeError: The "path" argument must be of type string or an instance of Buffer or URL. Received an instance of URL", source: internal/fs/utils.js (541)

To remedy this, I think we should instead switch on properties guaranteed to be present in all URL instances as specified by the WHATWG.

cc @jasnell

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

Merge request reports

Loading