Skip to content

Commit 1b7ebc2

Browse files
committed
url: preserve null char in WHATWG URL errors
A null character in the middle of an invalid URL was resulting in an error message that truncated the input string. This preserves the entire input string in the error message. Refs: #39592
1 parent eacd456 commit 1b7ebc2

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

lib/internal/url.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ function onParseComplete(flags, protocol, username, password,
559559
initSearchParams(this[searchParams], query);
560560
}
561561

562-
function onParseError(flags, input) {
562+
function onParseError(input, flags) {
563563
throw new ERR_INVALID_URL(input);
564564
}
565565

@@ -641,7 +641,8 @@ class URL {
641641
}
642642
this[context] = new URLContext();
643643
parse(input, -1, base_context, undefined,
644-
FunctionPrototypeBind(onParseComplete, this), onParseError);
644+
FunctionPrototypeBind(onParseComplete, this),
645+
FunctionPrototypeBind(onParseError, this, input));
645646
}
646647

647648
get [special]() {
@@ -760,7 +761,8 @@ class URL {
760761
// toUSVString is not needed.
761762
input = `${input}`;
762763
parse(input, -1, undefined, undefined,
763-
FunctionPrototypeBind(onParseComplete, this), onParseError);
764+
FunctionPrototypeBind(onParseComplete, this),
765+
FunctionPrototypeBind(onParseError, this, input));
764766
}
765767

766768
// readonly

src/node_url.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ URLHost::~URLHost() {
144144

145145
#define ERR_ARGS(XX) \
146146
XX(ERR_ARG_FLAGS) \
147-
XX(ERR_ARG_INPUT) \
148147

149148
enum url_cb_args {
150149
#define XX(name) name,
@@ -1681,8 +1680,6 @@ void Parse(Environment* env,
16811680
} else if (error_cb->IsFunction()) {
16821681
Local<Value> argv[2] = { undef, undef };
16831682
argv[ERR_ARG_FLAGS] = Integer::NewFromUnsigned(isolate, url.flags);
1684-
argv[ERR_ARG_INPUT] =
1685-
String::NewFromUtf8(env->isolate(), input).ToLocalChecked();
16861683
error_cb.As<Function>()->Call(context, recv, arraysize(argv), argv)
16871684
.FromMaybe(Local<Value>());
16881685
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
require('../common');
3+
const assert = require('assert');
4+
5+
assert.throws(
6+
() => { new URL('a\0b'); },
7+
{ input: 'a\0b' }
8+
);

0 commit comments

Comments
 (0)