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
13 changes: 8 additions & 5 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -169,7 +168,11 @@ void BindingData::PathToFileURL(const FunctionCallbackInfo<Value>& 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);
Expand Down Expand Up @@ -423,9 +426,9 @@ void BindingData::Parse(const FunctionCallbackInfo<Value>& args) {
}

void BindingData::Update(const FunctionCallbackInfo<Value>& 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<BindingData>();
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-url-pathtofileurl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading