delvedor / find-my-way

A crazy fast HTTP router

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parametric regex match fails with similar routes

subhero24 opened this issue · comments

Using two routes which start with a regex param, the second route which should match /b/static/ doesn't.

findMyWay.on('GET', '/:a(a)', () => {})
findMyWay.on('GET', '/:b(b)/static', () => {})

Here is a complete test:

'use strict'

const t = require('tap')
const test = t.test
const FindMyWay = require('../')

test('Parametric regex match with similar routes', (t) => {
  t.plan(1)
  const findMyWay = FindMyWay()

  findMyWay.on('GET', '/:a(a)', () => {})
  findMyWay.on('GET', '/:b(b)/static', () => {})

  t.same(findMyWay.find('GET', '/b/static', {}).params, { 'b': 'b' })
})

@subhero24 I was wrong here #280 (comment). We can resolve it because there would always be only one matched route. The problem if we add multiple parametric route support is to check that /:a(a)/static and /:b(b)/static can't be registered at the same time.