Skip to content

Underscores not working in named segments #32

@basicdays

Description

@basicdays

Hey all,

Just tried to have a named segment with an underscore, and found that it wasn't working as expected. I have a sample script and output to have as an example:

#!/usr/bin/env node
const UrlPattern = require('url-pattern');
const pattern = new UrlPattern('/test/:value_here');

console.dir(pattern);
console.log(pattern.match('/test/stuff'));
console.log(pattern.match('/test/stuff_here'));
UrlPattern {
  isRegex: false,
  ast:
   [ { tag: 'static', value: '/test/' },
     { tag: 'named', value: 'value' },
     { tag: 'static', value: '_here' } ],
  regex: /^\/test\/([a-zA-Z0-9-_~ %]+)_here$/,
  names: [ 'value' ] }
null
{ value: 'stuff' }

It seems to be parsing the underscore in the named segment as a static separator by accident.

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