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

Deno's URLPattern.exec(string) implementation differs from the node polyfill #28247

Open
NextLegacy opened this issue Feb 22, 2025 · 2 comments
Labels
needs investigation requires further investigation before determining if it is an issue or not

Comments

@NextLegacy
Copy link

Version: Deno 2.2.1

Heyy everyone,
It seems like 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.

Reproduction:

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 Behavior (Chrome/Node Polyfill):

{
  "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 Behavior (Deno):

{
  "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:

In Deno, the hostname.groups object does not contain the expected named group (domain), while in Chrome/Node's polyfill, it does ("groups": { "domain": "localhost" }). This discrepancy is causing some libraries that rely on the expected output format to break.

Is this an intentional difference, or could it be a bug in Deno’s implementation?

Thanks in advance!

@crowlKats crowlKats added the needs investigation requires further investigation before determining if it is an issue or not label Feb 22, 2025
@marvinhagemeister
Copy link
Contributor

Can confirm the issue. Something is off with the groups property.

@samuelstroschein
Copy link

Node's spec implementation (released in v23) yields the same result as the polyfill, further indicating that Deno's implementation has a bug.

import { URLPattern } from "node:url";

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);
{
  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: { path: undefined, locale: 'de' } },
  search: { input: '', groups: { '0': '' } },
  hash: { input: '', groups: { '0': '' } }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs investigation requires further investigation before determining if it is an issue or not
Projects
None yet
Development

No branches or pull requests

4 participants