From d59277a983ff7bfc6bebfed44562d8c4057ed506 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 13 Apr 2023 12:48:28 -0400 Subject: [PATCH] url: handle URL.canParse without base parameter --- src/node_url.cc | 2 +- test/parallel/test-whatwg-url-canparse.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-whatwg-url-canparse.js diff --git a/src/node_url.cc b/src/node_url.cc index 463de5f268ee95..1cb0a5fd210f36 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..8f8ada132b5ede --- /dev/null +++ b/test/parallel/test-whatwg-url-canparse.js @@ -0,0 +1,9 @@ +'use strict'; + +require('../common'); + +const { URL } = require('url'); +const assert = require('assert'); + +// It should not throw when called without a base string +assert.strictEqual(URL.canParse('https://example.org'), true);