Skip to content

Commit

Permalink
fixup! url: add experimental URLPattern
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Feb 25, 2022
1 parent a420bdf commit 0efafe2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/internal/urlpattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ function tryConsumeModifierToken(parser) {
function runEncoding(parser, value) {
if (value === '') return value;
try {
let parseResult = new URL(`${protocol}://dummy.test`);
let parseResult = new URL(`${parser.protocol||value}://dummy.test`);

switch (parser.type) {
case 'protocol':
Expand Down Expand Up @@ -689,7 +689,8 @@ function runEncoding(parser, value) {
}
// TODO(@jasnell): Throw proper error. Should be an assert
throw new TypeError('Unknown type');
} catch {
} catch (err) {
console.log(err);
// TODO(@jasnell): Throw proper error
throw new TypeError(`Invalid ${parser.type}`);
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-urlpattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ kTests.forEach((test) => {
});

{
// const pattern = new URLPattern({ pathname: '/books' });
const pattern = new URLPattern({ pathname: '/books' });
// console.log(pattern.test('https://example.com/books')); // true
// console.log(pattern.exec('https://example.com/books').pathname.groups); // {}
}
Expand Down

0 comments on commit 0efafe2

Please sign in to comment.