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
24 changes: 12 additions & 12 deletions src/node_url_pattern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,13 @@ MaybeLocal<Object> URLPattern::URLPatternComponentResult::ToJSObject(
auto tmpl = env->urlpatterncomponentresult_template();
if (tmpl.IsEmpty()) {
static constexpr std::string_view namesVec[] = {
"input",
"groups",
"input",
};
tmpl = DictionaryTemplate::New(isolate, namesVec);
env->set_urlpatterncomponentresult_template(tmpl);
}
MaybeLocal<Value> values[] = {input, parsed_group};
MaybeLocal<Value> values[] = {parsed_group, input};
return NewDictionaryInstance(env->context(), tmpl, values);
}

Expand All @@ -463,22 +463,24 @@ MaybeLocal<Value> URLPattern::URLPatternResult::ToJSValue(
auto tmpl = env->urlpatternresult_template();
if (tmpl.IsEmpty()) {
static constexpr std::string_view namesVec[] = {
"hash",
"hostname",
"inputs",
"protocol",
"username",
"password",
"hostname",
"port",
"pathname",
"port",
"protocol",
"search",
"hash",
"username",
};
tmpl = DictionaryTemplate::New(isolate, namesVec);
env->set_urlpatternresult_template(tmpl);
}

size_t index = 0;
MaybeLocal<Value> vals[] = {
URLPatternComponentResult::ToJSObject(env, result.hash),
URLPatternComponentResult::ToJSObject(env, result.hostname),
Array::New(env->context(),
result.inputs.size(),
[&index, &inputs = result.inputs, env]() {
Expand All @@ -493,14 +495,12 @@ MaybeLocal<Value> URLPattern::URLPatternResult::ToJSValue(
return URLPatternInit::ToJsObject(env, init);
}
}),
URLPatternComponentResult::ToJSObject(env, result.protocol),
URLPatternComponentResult::ToJSObject(env, result.username),
URLPatternComponentResult::ToJSObject(env, result.password),
URLPatternComponentResult::ToJSObject(env, result.hostname),
URLPatternComponentResult::ToJSObject(env, result.port),
URLPatternComponentResult::ToJSObject(env, result.pathname),
URLPatternComponentResult::ToJSObject(env, result.port),
URLPatternComponentResult::ToJSObject(env, result.protocol),
URLPatternComponentResult::ToJSObject(env, result.search),
URLPatternComponentResult::ToJSObject(env, result.hash)};
URLPatternComponentResult::ToJSObject(env, result.username)};
return NewDictionaryInstanceNullProto(env->context(), tmpl, vals);
}

Expand Down
24 changes: 24 additions & 0 deletions test/parallel/test-urlpattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,27 @@ assert.throws(() => {
}, {
message: 'boom'
});

{
const result = new URLPattern({ pathname: '/:value' })
.exec('https://example.com/test');

assert.deepStrictEqual(Object.keys(result), [
'hash',
'hostname',
'inputs',
'password',
'pathname',
'port',
'protocol',
'search',
'username',
]);
assert.deepStrictEqual(Object.keys(result.pathname), [
'groups',
'input',
]);
assert.strictEqual(result.hostname.input, 'example.com');
assert.strictEqual(result.pathname.input, '/test');
assert.strictEqual(result.pathname.groups.value, 'test');
}
Loading