Skip to content
Myr

refactor(trie-router): make `*` and `/*` have same priority (#274)

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

authored by Yusuke Wada · committed by GitHub · parent 938aa7f · Browse files · 2 files+24 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

2 files+24 added−2 removed

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

2 files+24 added−2 removed

modified:src/router/trie-router/node.test.ts+22 added
509 unmodified lines
510 expect(res).not.toBeNull()511 expect(res.handlers).toEqual(['a', 'b', 'entry'])512 })513})514515describe('star', () => {516 const node = new Node()517 node.insert('get', '/', '/')518 node.insert('get', '/*', '/*')519 node.insert('get', '*', '*')520521 node.insert('get', '/x', '/x')522 node.insert('get', '/x/*', '/x/*')523524 it('top', async () => {525 const res = node.search('get', '/')526 expect(res).not.toBeNull()527 expect(res.handlers).toEqual(['/*', '*', '/']) // => failed ['*', '/*', '/']528 })529530 it('Under a certain path', async () => {531 const res = node.search('get', '/x')532 expect(res).not.toBeNull()533 expect(res.handlers).toEqual(['/*', '*', '/x', '/x/*']) // => failed ['*', '/*', '/x', '/x/*']534 })535})
modified:src/router/trie-router/node.ts+2 added-2 removed
98 unmodified lines
99100 if (path === '*') {101 score = score + this.order * 0.01102 } else {103 score = parts.length + 1 + this.order * 0.01103 score = parts.length + this.order * 0.01104 }105106 if (!curNode.methods.length) {107 curNode.methods = []
39 unmodified lines
147 if (pattern === '*') {148 const astNode = node.children['*']149 if (astNode) {150 let wildcard = false151 if (!Object.keys(astNode.children).length) {151 if (astNode.methods.length) {152 wildcard = true153 }154 handlerSets.push(...this.getHandlerSets(astNode, method, wildcard))155 nextNodes.push(astNode)
82 unmodified lines