Skip to content
Myr

fix(trie-router): fixed the issue same param name is used (#1983)

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

* fix(trie-router): fixed the issue same param name is used * denoify

authored by Yusuke Wada · committed by GitHub · parent 4c2f575 · Browse files · 3 files+15 added−4 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+15 added−4 removed

  • tests:+13 added−0 removed
  • other:+2 added−4 removed

3 files+15 added−4 removed

modified:deno_dist/router/trie-router/node.ts+1 added-2 removed
109 unmodified lines
110 }111112 search(method: string, path: string): [[T, Params][]] {113 const handlerSets: HandlerParamsSet<T>[] = []114115 const params: Record<string, string> = {}114 this.params = {}115116 // eslint-disable-next-line @typescript-eslint/no-this-alias117 const curNode: Node<T> = this
22 unmodified lines
140 }141 }142143 for (let k = 0, len3 = node.patterns.length; k < len3; k++) {144 const params: Record<string, string> = {}145 const pattern = node.patterns[k]146147 // Wildcard148 // '/hello/*/foo' => match /hello/bar/foo
51 unmodified lines
modified:src/router/trie-router/node.test.ts+13 added
739 unmodified lines
740 expect(res[1][0]).toEqual('no-slug-b')741 expect(res[1][1]).toEqual({})742 })743})744745describe('The same name is used for path params', () => {746 const node = new Node()747 node.insert('get', '/:a', 'a')748 node.insert('get', '/:b/:a', 'ba')749 it('/about/me', () => {750 const [res] = node.search('get', '/about/me')751 expect(res).not.toBeNull()752 expect(res.length).toBe(1)753 expect(res[0][0]).toEqual('ba')754 expect(res[0][1]).toEqual({ b: 'about', a: 'me' })755 })756})
modified:src/router/trie-router/node.ts+1 added-2 removed
109 unmodified lines
110 }111112 search(method: string, path: string): [[T, Params][]] {113 const handlerSets: HandlerParamsSet<T>[] = []114115 const params: Record<string, string> = {}114 this.params = {}115116 // eslint-disable-next-line @typescript-eslint/no-this-alias117 const curNode: Node<T> = this
22 unmodified lines
140 }141 }142143 for (let k = 0, len3 = node.patterns.length; k < len3; k++) {144 const params: Record<string, string> = {}145 const pattern = node.patterns[k]146147 // Wildcard148 // '/hello/*/foo' => match /hello/bar/foo
51 unmodified lines