Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URLPattern.exec(string) implementation differs from the node polyfill #58

Open
adriannsemb opened this issue Mar 1, 2025 · 0 comments

Comments

@adriannsemb
Copy link

Hi,

I'm linking issue here from:

as this library contains the implementation of URLPattern for deno.


Deno's URLPattern.exec(string) implementation differs from the node polyfill, which is causing some libraries to behave inconsistently or even break when running in Deno.

const pattern = ":protocol://:domain(.*)::port?/:locale(de)?/:path(.*)?";
const url = "https://localhost:5173/de";

const urlpattern = new URLPattern(pattern);
const match = urlpattern.exec(url);

console.log(match);

expected

{
  "inputs": ["https://localhost:5173/de"],
  "protocol": { "input": "https", "groups": { "protocol": "https" } },
  "username": { "input": "", "groups": { "0": "" } },
  "password": { "input": "", "groups": { "0": "" } },
  "hostname": { "input": "localhost", "groups": { "domain": "localhost" } },   //<----------
  "port": { "input": "5173", "groups": { "port": "5173" } },
  "pathname": { "input": "/de", "groups": { "locale": "de", "path": undefined } },
  "search": { "input": "", "groups": { "0": "" } },
  "hash": { "input": "", "groups": { "0": "" } }
}

actual

{
  "inputs": ["https://localhost:5173/de"],
  "protocol": { "input": "https", "groups": { "protocol": "https" } },
  "username": { "input": "", "groups": { "0": "" } },
  "password": { "input": "", "groups": { "0": "" } },
  "hostname": { "input": "localhost", "groups": { "0": "localhost" } },        //<----------
  "port": { "input": "5173", "groups": { "port": "5173" } },
  "pathname": { "input": "/de", "groups": { "locale": "de", "path": undefined } },
  "search": { "input": "", "groups": { "0": "" } },
  "hash": { "input": "", "groups": { "0": "" } }
}

difference

hostname.groups object does not contain the expected named group (domain), while in Chrome/Node's polyfill, it does ("groups": { "domain": "localhost" }).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant