diff --git a/src/node_url.cc b/src/node_url.cc index 6294cd03667980..68dd40452eeec3 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -93,7 +93,6 @@ constexpr auto lookup_table = []() consteval { case CHAR: \ result[i] = {{'%', HEX_DIGIT_2, HEX_DIGIT_1, 0}}; \ break; - ENCODE_CHAR('\0', '0', '0') // '\0' == 0x00 ENCODE_CHAR('\t', '0', '9') // '\t' == 0x09 ENCODE_CHAR('\n', '0', 'A') // '\n' == 0x0A @@ -169,7 +168,11 @@ void BindingData::PathToFileURL(const FunctionCallbackInfo& args) { [[unlikely]] { CHECK(args[2]->IsString()); Utf8Value hostname(isolate, args[2]); - CHECK(out->set_hostname(hostname.ToStringView())); + if (!out->set_hostname(hostname.ToStringView())) { + return ThrowInvalidURL(realm->env(), + input.ToStringView(), + std::string(hostname.ToStringView())); + } } binding_data->UpdateComponents(out->get_components(), out->type); @@ -423,9 +426,9 @@ void BindingData::Parse(const FunctionCallbackInfo& args) { } void BindingData::Update(const FunctionCallbackInfo& args) { - CHECK(args[0]->IsString()); // href - CHECK(args[1]->IsNumber()); // action type - CHECK(args[2]->IsString()); // new value + CHECK(args[0]->IsString()); // href + CHECK(args[1]->IsNumber()); // action type + CHECK(args[2]->IsString()); // new value Realm* realm = Realm::GetCurrent(args); BindingData* binding_data = realm->GetBindingData(); diff --git a/test/parallel/test-url-pathtofileurl.js b/test/parallel/test-url-pathtofileurl.js index 089232caeb3b2d..01d27f2b736d75 100644 --- a/test/parallel/test-url-pathtofileurl.js +++ b/test/parallel/test-url-pathtofileurl.js @@ -21,6 +21,14 @@ const url = require('url'); assert.ok(fileURL.includes('%25')); } +{ + assert.throws(() => { + url.pathToFileURL('\\\\exa mple\\share\\file.txt', { windows: true }); + }, { + code: 'ERR_INVALID_URL', + }); +} + { if (isWindows) { // UNC path: \\server\share\resource