Skip to content

Commit

Permalink
Fix URLPattern port handling (#1881)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell authored Mar 23, 2024
1 parent bfcfe9a commit e02ae1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/workerd/api/tests/url-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9769,3 +9769,12 @@ export const urlPatternFun = {
}
}
};

export const urlPatternPortRegression = {
test() {
const pattern = new URLPattern({pathname: "/graphql"});
const url = new URL("http://localhost:53000/");
// Shouldn't match, but also shouldn't throw
ok(!pattern.test(url));
}
};
2 changes: 1 addition & 1 deletion src/workerd/jsg/url.c++
Original file line number Diff line number Diff line change
Expand Up @@ -2223,7 +2223,7 @@ UrlPattern::Result<UrlPattern::Init> UrlPattern::processInit(
result.hostname = kj::str(url.getHostname());
}
KJ_IF_SOME(port, chooseStr(kj::mv(init.port), options.port)) {
if (port.size() >= 5 || !std::all_of(port.begin(), port.end(), isAsciiDigit)) {
if (port.size() > 5 || !std::all_of(port.begin(), port.end(), isAsciiDigit)) {
return kj::str("Invalid URL port component");
}
if (port.size() == 0) {
Expand Down

0 comments on commit e02ae1f

Please sign in to comment.