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

url: handle URL.canParse without base parameter #47547

Merged
merged 1 commit into from
Apr 14, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void BindingData::DomainToUnicode(const FunctionCallbackInfo<Value>& args) {

// TODO(@anonrig): Add V8 Fast API for CanParse method
void BindingData::CanParse(const FunctionCallbackInfo<Value>& args) {
CHECK_GE(args.Length(), 2);
CHECK_GE(args.Length(), 1);
CHECK(args[0]->IsString()); // input
// args[1] // base url

Expand Down
21 changes: 21 additions & 0 deletions test/parallel/test-whatwg-url-canparse.js
Original file line number Diff line number Diff line change
@@ -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);