From 6b70bd901d2e459b68abd7801effa2e47addbe26 Mon Sep 17 00:00:00 2001 From: Burkov Egor Date: Tue, 31 Mar 2026 10:16:38 +0300 Subject: [PATCH 1/2] src: improve error handling for triggered assertions --- src/node_url.cc | 10 ++++++++-- test/parallel/test-url-format-whatwg.js | 2 ++ test/parallel/test-url-pathtofileurl.js | 7 +++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/node_url.cc b/src/node_url.cc index 6294cd03667980..66c25654b35a40 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -169,7 +169,10 @@ void BindingData::PathToFileURL(const FunctionCallbackInfo& args) { [[unlikely]] { CHECK(args[2]->IsString()); Utf8Value hostname(isolate, args[2]); - CHECK(out->set_hostname(hostname.ToStringView())); + // Ada should validate chars in hostname + if(!out->set_hostname(hostname.ToStringView())) { + return ThrowInvalidURL(realm->env(), input.ToStringView(), std::nullopt); + } } binding_data->UpdateComponents(out->get_components(), out->type); @@ -441,7 +444,10 @@ void BindingData::Update(const FunctionCallbackInfo& args) { std::string_view new_value_view = new_value.ToStringView(); auto out = ada::parse(input.ToStringView()); - CHECK(out); + // If the href cannot be re-parsed, return original url + if (!out) { + return args.GetReturnValue().Set(false); + } bool result{true}; diff --git a/test/parallel/test-url-format-whatwg.js b/test/parallel/test-url-format-whatwg.js index 12594335d6bd67..021cb0093c3024 100644 --- a/test/parallel/test-url-format-whatwg.js +++ b/test/parallel/test-url-format-whatwg.js @@ -154,4 +154,6 @@ test('should not crash on URLs with invalid IDN hostnames', () => { const u = new URL('ws:xn-\u022B'); // doesNotThrow url.format(u, { fragment: false, unicode: false, auth: false, search: false }); + // Same problem with re-parsing + url.port = 80; }); diff --git a/test/parallel/test-url-pathtofileurl.js b/test/parallel/test-url-pathtofileurl.js index 089232caeb3b2d..d20983ca9d1a13 100644 --- a/test/parallel/test-url-pathtofileurl.js +++ b/test/parallel/test-url-pathtofileurl.js @@ -223,3 +223,10 @@ for (const { path, expected } of testCases) { }); } } + +// Regression for forbidden chars in UNC Windows +{ + assert.throws(() => url.pathToFileURL('\\\\%\\file', {windows : true}), { + code: 'ERR_INVALID_URL', + }); +} \ No newline at end of file From 0e28c2de8e259ca095e508370ac64ca697d17b8b Mon Sep 17 00:00:00 2001 From: Burkov Egor Date: Tue, 31 Mar 2026 10:51:16 +0300 Subject: [PATCH 2/2] lint --- src/node_url.cc | 2 +- test/parallel/test-url-pathtofileurl.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/node_url.cc b/src/node_url.cc index 66c25654b35a40..ea56a415fe73aa 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -170,7 +170,7 @@ void BindingData::PathToFileURL(const FunctionCallbackInfo& args) { CHECK(args[2]->IsString()); Utf8Value hostname(isolate, args[2]); // Ada should validate chars in hostname - if(!out->set_hostname(hostname.ToStringView())) { + if (!out->set_hostname(hostname.ToStringView())) { return ThrowInvalidURL(realm->env(), input.ToStringView(), std::nullopt); } } diff --git a/test/parallel/test-url-pathtofileurl.js b/test/parallel/test-url-pathtofileurl.js index d20983ca9d1a13..9dac35cfc4de0f 100644 --- a/test/parallel/test-url-pathtofileurl.js +++ b/test/parallel/test-url-pathtofileurl.js @@ -226,7 +226,7 @@ for (const { path, expected } of testCases) { // Regression for forbidden chars in UNC Windows { - assert.throws(() => url.pathToFileURL('\\\\%\\file', {windows : true}), { - code: 'ERR_INVALID_URL', - }); -} \ No newline at end of file + assert.throws(() => url.pathToFileURL('\\\\%\\file', { windows: true }), { + code: 'ERR_INVALID_URL', + }); +}