No flags found
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
caf2802
... +0 ...
d4ca9a0
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
118 | 118 | fullPath string |
|
119 | 119 | } |
|
120 | 120 | ||
121 | - | type skip struct { |
|
122 | - | path string |
|
123 | - | paramNode *node |
|
124 | - | } |
|
125 | - | ||
126 | 121 | // Increments priority of the given child and reorders if necessary |
|
127 | 122 | func (n *node) incrementChildPrio(pos int) int { |
|
128 | 123 | cs := n.children |
405 | 400 | // made if a handle exists with an extra (without the) trailing slash for the |
|
406 | 401 | // given path. |
|
407 | 402 | func (n *node) getValue(path string, params *Params, unescape bool) (value nodeValue) { |
|
408 | - | var skipped *skip |
|
403 | + | // path: /abc/123/def |
|
404 | + | // level 1 router:abc |
|
405 | + | // level 2 router:123 |
|
406 | + | // level 3 router:def |
|
407 | + | var ( |
|
408 | + | skippedPath string |
|
409 | + | latestNode = n // not found `level 2 router` use latestNode |
|
410 | + | ||
411 | + | // match '/' count |
|
412 | + | // matchNum < 1: `level 2 router` not found,the current node needs to be equal to latestNode |
|
413 | + | // matchNum >= 1: `level (2 or 3 or 4 or ...) router`: Normal handling |
|
414 | + | matchNum int // each match will accumulate |
|
415 | + | ) |
|
416 | + | //if path == "/", no need to look for tree node |
|
417 | + | if len(path) == 1 { |
|
418 | + | matchNum = 1 |
|
419 | + | } |
|
409 | 420 | ||
410 | 421 | walk: // Outer loop for walking the tree |
|
411 | 422 | for { |
418 | 429 | idxc := path[0] |
|
419 | 430 | for i, c := range []byte(n.indices) { |
|
420 | 431 | if c == idxc { |
|
421 | - | if strings.HasPrefix(n.children[len(n.children)-1].path, ":") { |
|
422 | - | skipped = &skip{ |
|
423 | - | path: prefix + path, |
|
424 | - | paramNode: &node{ |
|
425 | - | path: n.path, |
|
426 | - | wildChild: n.wildChild, |
|
427 | - | nType: n.nType, |
|
428 | - | priority: n.priority, |
|
429 | - | children: n.children, |
|
430 | - | handlers: n.handlers, |
|
431 | - | fullPath: n.fullPath, |
|
432 | - | }, |
|
432 | + | // strings.HasPrefix(n.children[len(n.children)-1].path, ":") == n.wildChild |
|
433 | + | if n.wildChild { |
|
434 | + | skippedPath = prefix + path |
|
435 | + | latestNode = &node{ |
|
436 | + | path: n.path, |
|
437 | + | wildChild: n.wildChild, |
|
438 | + | nType: n.nType, |
|
439 | + | priority: n.priority, |
|
440 | + | children: n.children, |
|
441 | + | handlers: n.handlers, |
|
442 | + | fullPath: n.fullPath, |
|
433 | 443 | } |
|
434 | 444 | } |
|
435 | 445 | ||
436 | 446 | n = n.children[i] |
|
447 | + | ||
448 | + | // match '/', If this condition is matched, the next route is found |
|
449 | + | if (len(n.fullPath) != 0 && n.wildChild) || path[len(path)-1] == '/' { |
|
450 | + | matchNum++ |
|
451 | + | } |
|
437 | 452 | continue walk |
|
438 | 453 | } |
|
439 | 454 | } |
|
440 | 455 | ||
456 | + | // level 2 router not found,the current node needs to be equal to latestNode |
|
457 | + | if matchNum < 1 { |
|
458 | + | n = latestNode |
|
459 | + | } |
|
460 | + | ||
441 | 461 | // If there is no wildcard pattern, recommend a redirection |
|
442 | 462 | if !n.wildChild { |
|
443 | 463 | // Nothing found. |
|
444 | 464 | // We can recommend to redirect to the same URL without a |
|
445 | 465 | // trailing slash if a leaf exists for that path. |
|
446 | - | value.tsr = (path == "/" && n.handlers != nil) |
|
466 | + | value.tsr = path == "/" && n.handlers != nil |
|
447 | 467 | return |
|
448 | 468 | } |
|
449 | 469 |
483 | 503 | if len(n.children) > 0 { |
|
484 | 504 | path = path[end:] |
|
485 | 505 | n = n.children[0] |
|
506 | + | // next node,the latestNode needs to be equal to currentNode and handle next router |
|
507 | + | latestNode = n |
|
508 | + | // not found router in (level 1 router and handle next node),skippedPath cannot execute |
|
509 | + | // example: |
|
510 | + | // * /:cc/cc |
|
511 | + | // call /a/cc expectations:match/200 Actual:match/200 |
|
512 | + | // call /a/dd expectations:unmatch/404 Actual: panic |
|
513 | + | // call /addr/dd/aa expectations:unmatch/404 Actual: panic |
|
514 | + | // skippedPath: It can only be executed if the secondary route is not found |
|
515 | + | // matchNum: Go to the next level of routing tree node search,need add matchNum |
|
516 | + | skippedPath = "" |
|
517 | + | matchNum++ |
|
486 | 518 | continue walk |
|
487 | 519 | } |
|
488 | 520 |
535 | 567 | } |
|
536 | 568 | ||
537 | 569 | if path == prefix { |
|
570 | + | // level 2 router not found and latestNode.wildChild is true |
|
571 | + | if matchNum < 1 && latestNode.wildChild { |
|
572 | + | n = latestNode.children[len(latestNode.children)-1] |
|
573 | + | } |
|
538 | 574 | // We should have reached the node containing the handle. |
|
539 | 575 | // Check if this node has a handle registered. |
|
540 | 576 | if value.handlers = n.handlers; value.handlers != nil { |
564 | 600 | return |
|
565 | 601 | } |
|
566 | 602 | ||
567 | - | if path != "/" && skipped != nil && strings.HasSuffix(skipped.path, path) { |
|
568 | - | path = skipped.path |
|
569 | - | n = skipped.paramNode |
|
570 | - | skipped = nil |
|
603 | + | // path != "/" && skippedPath != "" |
|
604 | + | if len(path) != 1 && len(skippedPath) > 0 && strings.HasSuffix(skippedPath, path) { |
|
605 | + | path = skippedPath |
|
606 | + | n = latestNode |
|
607 | + | skippedPath = "" |
|
571 | 608 | continue walk |
|
572 | 609 | } |
|
573 | 610 | ||
574 | 611 | // Nothing found. We can recommend to redirect to the same URL with an |
|
575 | 612 | // extra trailing slash if a leaf exists for that path |
|
576 | - | value.tsr = (path == "/") || |
|
577 | - | (len(prefix) == len(path)+1 && prefix[len(path)] == '/' && |
|
578 | - | path == prefix[:len(prefix)-1] && n.handlers != nil) |
|
613 | + | value.tsr = path == "/" || |
|
614 | + | (len(prefix) == len(path)+1 && n.handlers != nil) |
|
579 | 615 | return |
|
580 | 616 | } |
|
581 | 617 | } |
Files | Coverage |
---|---|
Project Totals (41 files) | 98.71% |
d4ca9a0
caf2802