Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ void BindingData::PathToFileURL(const FunctionCallbackInfo<Value>& 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);
Expand Down Expand Up @@ -441,7 +444,10 @@ void BindingData::Update(const FunctionCallbackInfo<Value>& args) {

std::string_view new_value_view = new_value.ToStringView();
auto out = ada::parse<ada::url_aggregator>(input.ToStringView());
CHECK(out);
// If the href cannot be re-parsed, return original url
if (!out) {
return args.GetReturnValue().Set(false);
}

bool result{true};

Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-url-format-whatwg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
7 changes: 7 additions & 0 deletions test/parallel/test-url-pathtofileurl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
}
Loading