Skip to content
Myr

Fix Trie router multiple matching path parameters (#571)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Failing test for prefix parameters * Fix test by removing break * Denoify

authored by Nicholas Gates · committed by GitHub · parent 9a0389e · Browse files · 3 files+22 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+22 added−2 removed

  • tests:+22 added−0 removed
  • other:+0 added−2 removed

3 files+22 added−2 removed

modified:deno_dist/router/trie-router/node.ts-1 removed
185 unmodified lines
186 // GET /book/foo ~> slug, param['slug'] => foo187 if (typeof name === 'string' && !matched) {188 params[name] = part189 }190 break190 }191 }192 }193
18 unmodified lines
modified:src/router/trie-router/node.test.ts+22 added
103 unmodified lines
104 expect(res?.params['id']).toBe('123')105 })106})107108describe('Param prefix', () => {109 const node = new Node()110111 node.insert('get', '/:foo', 'onepart')112 node.insert('get', '/:bar/:baz', 'twopart')113114 it('get /hello', () => {115 const res = node.search('get', '/hello')116 expect(res).not.toBeNull()117 expect(res?.handlers).toEqual(['onepart'])118 expect(res?.params['foo']).toBe('hello')119 })120121 it('get /hello/world', () => {122 const res = node.search('get', '/hello/world')123 expect(res).not.toBeNull()124 expect(res?.handlers).toEqual(['twopart'])125 expect(res?.params['bar']).toBe('hello')126 expect(res?.params['baz']).toBe('world')127 })128})129130describe('Wildcard', () => {131 const node = new Node()132 node.insert('get', '/wildcard-abc/*/wildcard-efg', 'wildcard')133 it('/wildcard-abc/xxxxxx/wildcard-efg', () => {
436 unmodified lines
modified:src/router/trie-router/node.ts-1 removed
185 unmodified lines
186 // GET /book/foo ~> slug, param['slug'] => foo187 if (typeof name === 'string' && !matched) {188 params[name] = part189 }190 break190 }191 }192 }193
18 unmodified lines