Skip to content

Execution times with double star syntax and dashes #121

@lenovouser

Description

@lenovouser

Platform: macOS
Architecture: arm64
Node: v18.18.0

The double-star syntax is unnecessary, since it also works with a single star, but I still want to report this to hopefully get it fixed.

If you execute the code below:

  • Example 1 runs fine
  • Example 2 takes about 20 seconds
  • Example 3 never ends and freezes the event loop completely (not entirely sure, but it seems like it) - including HTTP servers running in the same process. In case you make the mistake to have double stars somewhere in your patterns this makes your service extremely vulnerable to DOS attacks.
const { URLPattern } = require('urlpattern-polyfill');

const pattern = new URLPattern({ hostname: '**.google.com' });

const check = value => {
    if (pattern.test(value)) {
        return;
    }

    return value;
};

const start1 = process.hrtime.bigint();
const result1 = check('https://example.com');
const end1 = process.hrtime.bigint();

console.log(result1);
console.log('took ' + (end1 - start1) / 1000n + 'ms');

const start2 = process.hrtime.bigint();
const result2 = check('https://subdomain.subdomain.example.com');
const end2 = process.hrtime.bigint();

console.log(result2);
console.log('took ' + (end2 - start2) / 1_000_000n + 's');

const start3 = process.hrtime.bigint();
const result3 = check('https://dash-subdomain.subdomain.example.com');
const end3 = process.hrtime.bigint();

console.log(result3);
console.log('took ' + (end3 - start3) / 1_000_000n + 's');

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions