Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fe01940

Browse filesBrowse files
Trottbengl
authored andcommitted
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 PR-URL: #42263 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 94e5eaa commit fe01940
Copy full SHA for fe01940

File tree

Expand file treeCollapse file tree

3 files changed

+15
-19
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+15
-19
lines changed
Open diff view settings
Collapse file

‎lib/internal/url.js‎

Copy file name to clipboardExpand all lines: lib/internal/url.js
+5-3Lines 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
Collapse file

‎src/node_url.cc‎

Copy file name to clipboardExpand all lines: src/node_url.cc
+2-16Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -142,22 +142,12 @@ URLHost::~URLHost() {
142142
XX(ARG_FRAGMENT) \
143143
XX(ARG_COUNT) // This one has to be last.
144144

145-
#define ERR_ARGS(XX) \
146-
XX(ERR_ARG_FLAGS) \
147-
XX(ERR_ARG_INPUT) \
148-
149145
enum url_cb_args {
150146
#define XX(name) name,
151147
ARGS(XX)
152148
#undef XX
153149
};
154150

155-
enum url_error_cb_args {
156-
#define XX(name) name,
157-
ERR_ARGS(XX)
158-
#undef XX
159-
};
160-
161151
#define TWO_CHAR_STRING_TEST(bits, name, expr) \
162152
template <typename T> \
163153
bool name(const T ch1, const T ch2) { \
@@ -1679,12 +1669,8 @@ void Parse(Environment* env,
16791669
SetArgs(env, argv, url);
16801670
cb->Call(context, recv, arraysize(argv), argv).FromMaybe(Local<Value>());
16811671
} else if (error_cb->IsFunction()) {
1682-
Local<Value> argv[2] = { undef, undef };
1683-
argv[ERR_ARG_FLAGS] = Integer::NewFromUnsigned(isolate, url.flags);
1684-
argv[ERR_ARG_INPUT] =
1685-
String::NewFromUtf8(env->isolate(), input).ToLocalChecked();
1686-
error_cb.As<Function>()->Call(context, recv, arraysize(argv), argv)
1687-
.FromMaybe(Local<Value>());
1672+
Local<Value> flags = Integer::NewFromUnsigned(isolate, url.flags);
1673+
USE(error_cb.As<Function>()->Call(context, recv, 1, &flags));
16881674
}
16891675
}
16901676

Collapse file
+8Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.