GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — url: handle unparsable serialized URLs in setters · nodejs/node@9ffc0da

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_url.cc
  • test/parallel
    • test-whatwg-url-custom-setters.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_url.cc‎

Copy file name to clipboardExpand all lines: src/node_url.cc
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,12 @@ void BindingData::Update(const FunctionCallbackInfo<Value>& args) {
443443
Utf8Value new_value(isolate, args[2].As<String>());
444444

445445
std::string_view new_value_view = new_value.ToStringView();
446+
// A serialized URL is not always reparsable: the IDNA encoder can emit a
447+
// host label that the decoder rejects. Fail the update instead of crashing.
446448
auto out = ada::parse<ada::url_aggregator>(input.ToStringView());
447-
CHECK(out);
449+
if (!out) {
450+
return args.GetReturnValue().Set(false);
451+
}
448452

449453
bool result{true};
450454

Collapse file

‎test/parallel/test-whatwg-url-custom-setters.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-url-custom-setters.js
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,32 @@ const additionalTestCases =
3939
}
4040
}
4141

42+
// The parser can produce a serialization it rejects when parsing it back: a
43+
// Unicode host encodes to an `xn--xn--` label that the punycode decoder turns
44+
// down. Setters reparse `href`, so the failure must not take the process down.
45+
// Implementations backed by ICU accept that label, and ada does too as of
46+
// https://github.com/ada-url/idna/pull/72, so this URL round-trips once that
47+
// lands here and the setters below apply as usual.
48+
test(function() {
49+
const url = new URL('http:\u{1F600}xn-');
50+
const setters = {
51+
hostname: 'example.com',
52+
host: 'example.com:8080',
53+
protocol: 'https:',
54+
pathname: '/path',
55+
search: '?search',
56+
hash: '#hash',
57+
port: '8080',
58+
username: 'username',
59+
password: 'password',
60+
};
61+
62+
for (const [property, value] of Object.entries(setters)) {
63+
url[property] = value;
64+
assert_equals(typeof url.href, 'string', `Setting ${property} does not crash`);
65+
}
66+
}, 'URL: setting properties with an unparsable serialized URL');
67+
4268
{
4369
const url = new URL('http://example.com/');
4470
const obj = {

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.