25
25
'~': 126 - ~
26
26
*/
27
27
28
- const assert = require ( 'assert' )
28
+ const assert = require ( 'node: assert' )
29
29
const querystring = require ( 'fast-querystring' )
30
30
const isRegexSafe = require ( 'safe-regex2' )
31
31
const deepEqual = require ( 'fast-deep-equal' )
@@ -344,7 +344,6 @@ Router.prototype.findRoute = function findNode (method, path, constraints = {})
344
344
const isRegexParam = charCode === 40
345
345
const isStaticPart = charCode === 45 || charCode === 46
346
346
const isEndOfNode = charCode === 47 || j === pattern . length
347
-
348
347
if ( isRegexParam || isStaticPart || isEndOfNode ) {
349
348
const paramName = pattern . slice ( lastParamStartIndex , j )
350
349
params . push ( paramName )
@@ -407,9 +406,7 @@ Router.prototype.findRoute = function findNode (method, path, constraints = {})
407
406
// add the wildcard parameter
408
407
params . push ( '*' )
409
408
currentNode = currentNode . getWildcardChild ( )
410
- if ( currentNode === null ) {
411
- return null
412
- }
409
+
413
410
parentNodePathIndex = i + 1
414
411
415
412
if ( i !== pattern . length - 1 ) {
@@ -422,10 +419,6 @@ Router.prototype.findRoute = function findNode (method, path, constraints = {})
422
419
pattern = pattern . toLowerCase ( )
423
420
}
424
421
425
- if ( pattern === '*' ) {
426
- pattern = '/*'
427
- }
428
-
429
422
for ( const existRoute of this . routes ) {
430
423
const routeConstraints = existRoute . opts . constraints || { }
431
424
if (
@@ -436,7 +429,7 @@ Router.prototype.findRoute = function findNode (method, path, constraints = {})
436
429
return {
437
430
handler : existRoute . handler ,
438
431
store : existRoute . store ,
439
- params : existRoute . params || [ ]
432
+ params : existRoute . params
440
433
}
441
434
}
442
435
}
@@ -642,37 +635,36 @@ Router.prototype.find = function find (method, path, derivedConstraints) {
642
635
continue
643
636
}
644
637
645
- if ( currentNode . kind === NODE_TYPES . PARAMETRIC ) {
646
- let paramEndIndex = originPath . indexOf ( '/' , pathIndex )
647
- if ( paramEndIndex === - 1 ) {
648
- paramEndIndex = pathLen
649
- }
638
+ // parametric node
639
+ let paramEndIndex = originPath . indexOf ( '/' , pathIndex )
640
+ if ( paramEndIndex === - 1 ) {
641
+ paramEndIndex = pathLen
642
+ }
650
643
651
- let param = originPath . slice ( pathIndex , paramEndIndex )
652
- if ( shouldDecodeParam ) {
653
- param = safeDecodeURIComponent ( param )
654
- }
644
+ let param = originPath . slice ( pathIndex , paramEndIndex )
645
+ if ( shouldDecodeParam ) {
646
+ param = safeDecodeURIComponent ( param )
647
+ }
655
648
656
- if ( currentNode . isRegex ) {
657
- const matchedParameters = currentNode . regex . exec ( param )
658
- if ( matchedParameters === null ) continue
649
+ if ( currentNode . isRegex ) {
650
+ const matchedParameters = currentNode . regex . exec ( param )
651
+ if ( matchedParameters === null ) continue
659
652
660
- for ( let i = 1 ; i < matchedParameters . length ; i ++ ) {
661
- const matchedParam = matchedParameters [ i ]
662
- if ( matchedParam . length > maxParamLength ) {
663
- return null
664
- }
665
- params . push ( matchedParam )
666
- }
667
- } else {
668
- if ( param . length > maxParamLength ) {
653
+ for ( let i = 1 ; i < matchedParameters . length ; i ++ ) {
654
+ const matchedParam = matchedParameters [ i ]
655
+ if ( matchedParam . length > maxParamLength ) {
669
656
return null
670
657
}
671
- params . push ( param )
658
+ params . push ( matchedParam )
672
659
}
673
-
674
- pathIndex = paramEndIndex
660
+ } else {
661
+ if ( param . length > maxParamLength ) {
662
+ return null
663
+ }
664
+ params . push ( param )
675
665
}
666
+
667
+ pathIndex = paramEndIndex
676
668
}
677
669
}
678
670
@@ -742,8 +734,6 @@ for (const i in httpMethods) {
742
734
const m = httpMethods [ i ]
743
735
const methodName = m . toLowerCase ( )
744
736
745
- if ( Router . prototype [ methodName ] ) throw new Error ( 'Method already exists: ' + methodName )
746
-
747
737
Router . prototype [ methodName ] = function ( path , handler , store ) {
748
738
return this . on ( m , path , handler , store )
749
739
}
0 commit comments