Skip to content
Myr

fix(trie-router): pass params to the next node (#1852)

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

* fix(trie-router): pass params to the next node * denoify

authored by Yusuke Wada · committed by GitHub · parent 0a9a753 · Browse files · 3 files+10 added−0 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+10 added−0 removed

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

3 files+10 added−0 removed

modified:deno_dist/router/trie-router/node.ts+1 added
128 unmodified lines
129 const node = curNodes[j]130 const nextNode = node.children[part]131132 if (nextNode) {133 nextNode.params = node.params134 if (isLast === true) {135 // '/hello/*' => match '/hello'136 if (nextNode.children['*']) {137 handlerSets.push(...this.gHSets(nextNode.children['*'], method, node.params))
63 unmodified lines
modified:src/router/trie-router/node.test.ts+8 added
58 unmodified lines
59 const node = new Node()60 node.insert('get', '/entry/:id', 'get entry')61 node.insert('get', '/entry/:id/comment/:comment_id', 'get comment')62 node.insert('get', '/map/:location/events', 'get events')63 node.insert('get', '/about/:name/address/map', 'get address')6465 it('get /entry/123', () => {66 const [res] = node.search('get', '/entry/123')67 expect(res.length).toBe(1)
22 unmodified lines
90 expect(res[0][0]).toEqual('get events')91 expect(res[0][1]['location']).toBe('yokohama')92 })9394 it('get /about/:name/address/map', () => {95 const [res] = node.search('get', '/about/foo/address/map')96 expect(res.length).toBe(1)97 expect(res[0][0]).toEqual('get address')98 expect(res[0][1]['name']).toBe('foo')99 })100101 it('Should not return a previous param value', () => {102 const node = new Node()103 node.insert('delete', '/resource/:id', 'resource')104 const [resA] = node.search('delete', '/resource/a')
639 unmodified lines
modified:src/router/trie-router/node.ts+1 added
128 unmodified lines
129 const node = curNodes[j]130 const nextNode = node.children[part]131132 if (nextNode) {133 nextNode.params = node.params134 if (isLast === true) {135 // '/hello/*' => match '/hello'136 if (nextNode.children['*']) {137 handlerSets.push(...this.gHSets(nextNode.children['*'], method, node.params))
63 unmodified lines