diff --git a/src/node_url.cc b/src/node_url.cc index 551e726145f06b..ca0d064281c23c 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -115,7 +115,7 @@ void BindingData::DomainToUnicode(const FunctionCallbackInfo& args) { // TODO(@anonrig): Add V8 Fast API for CanParse method void BindingData::CanParse(const FunctionCallbackInfo& args) { - CHECK_GE(args.Length(), 2); + CHECK_GE(args.Length(), 1); CHECK(args[0]->IsString()); // input // args[1] // base url diff --git a/test/parallel/test-whatwg-url-canparse.js b/test/parallel/test-whatwg-url-canparse.js new file mode 100644 index 00000000000000..5edda72979164e --- /dev/null +++ b/test/parallel/test-whatwg-url-canparse.js @@ -0,0 +1,21 @@ +// Flags: --expose-internals +'use strict'; + +require('../common'); + +const { URL } = require('url'); +const assert = require('assert'); + +let internalBinding; +try { + internalBinding = require('internal/test/binding').internalBinding; +} catch (e) { + console.log('using `test/parallel/test-whatwg-url-canparse` requires `--expose-internals`'); + throw e; +} + +const { canParse } = internalBinding('url'); + +// It should not throw when called without a base string +assert.strictEqual(URL.canParse('https://example.org'), true); +assert.strictEqual(canParse('https://example.org'), true);