Skip to content
Myr

fix(trie-router): fix same parameter name issue (#2136)

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

* fix(trie-router): fix same parameter name issue * denoify

authored by Yusuke Wada · committed by GitHub · parent dc39e02 · Browse files · 3 files+23 added−6 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+23 added−6 removed

  • tests:+15 added−0 removed
  • other:+8 added−6 removed

3 files+23 added−6 removed

modified:deno_dist/router/trie-router/node.ts+4 added-3 removed
117 unmodified lines
118119 search(method: string, path: string): [[T, Params][]] {120 const handlerSets: HandlerParamsSet<T>[] = []121 this.params = {}122 const params: Record<string, string> = {}122123 // eslint-disable-next-line @typescript-eslint/no-this-alias124 const curNode: Node<T> = this125 let curNodes = [curNode]
23 unmodified lines
149150 for (let k = 0, len3 = node.patterns.length; k < len3; k++) {151 const pattern = node.patterns[k]152153 const params = { ...node.params }154155 // Wildcard156 // '/hello/*/foo' => match /hello/bar/foo157 if (pattern === '*') {158 const astNode = node.children['*']
25 unmodified lines
184 params[name] = part185 if (isLast === true) {186 handlerSets.push(...this.gHSets(child, method, params, node.params))187 if (child.children['*']) {187 handlerSets.push(...this.gHSets(child.children['*'], method, node.params, params))188 handlerSets.push(...this.gHSets(child.children['*'], method, params, node.params))189 }190 } else {190 child.params = { ...params }191 child.params = params192 tempNodes.push(child)193 }194 }195 }
12 unmodified lines
modified:src/router/trie-router/node.test.ts+15 added
766 unmodified lines
767 expect(res[0][0]).toEqual('ba')768 expect(res[0][1]).toEqual({ b: 'about', a: 'me' })769 })770 })771772 describe('Complex with tails', () => {773 const node = new Node()774 node.insert('get', '/:id/:id2/comments', 'a')775 node.insert('get', '/posts/:id/comments', 'b')776 it('/posts/123/comments', () => {777 const [res] = node.search('get', '/posts/123/comments')778 expect(res).not.toBeNull()779 expect(res.length).toBe(2)780 expect(res[0][0]).toEqual('a')781 expect(res[0][1]).toEqual({ id: 'posts', id2: '123' })782 expect(res[1][0]).toEqual('b')783 expect(res[1][1]).toEqual({ id: '123' })784 })785 })786})
modified:src/router/trie-router/node.ts+4 added-3 removed
117 unmodified lines
118119 search(method: string, path: string): [[T, Params][]] {120 const handlerSets: HandlerParamsSet<T>[] = []121 this.params = {}122 const params: Record<string, string> = {}122123 // eslint-disable-next-line @typescript-eslint/no-this-alias124 const curNode: Node<T> = this125 let curNodes = [curNode]
23 unmodified lines
149150 for (let k = 0, len3 = node.patterns.length; k < len3; k++) {151 const pattern = node.patterns[k]152153 const params = { ...node.params }154155 // Wildcard156 // '/hello/*/foo' => match /hello/bar/foo157 if (pattern === '*') {158 const astNode = node.children['*']
25 unmodified lines
184 params[name] = part185 if (isLast === true) {186 handlerSets.push(...this.gHSets(child, method, params, node.params))187 if (child.children['*']) {187 handlerSets.push(...this.gHSets(child.children['*'], method, node.params, params))188 handlerSets.push(...this.gHSets(child.children['*'], method, params, node.params))189 }190 } else {190 child.params = { ...params }191 child.params = params192 tempNodes.push(child)193 }194 }195 }
12 unmodified lines