resolve code about deepsource test case

* Empty string test can be improved CRT-A0004
This commit is contained in:
t29kida 2021-05-21 17:44:04 +09:00
parent 819ec2164c
commit 068573bfe3

View File

@ -284,7 +284,7 @@ func (t *Tree) addseg(segments []string, route interface{}, wildcards []string,
// Match router to runObject & params // Match router to runObject & params
func (t *Tree) Match(pattern string, ctx *context.Context) (runObject interface{}) { func (t *Tree) Match(pattern string, ctx *context.Context) (runObject interface{}) {
if len(pattern) == 0 || pattern[0] != '/' { if pattern == "" || pattern[0] != '/' {
return nil return nil
} }
w := make([]string, 0, 20) w := make([]string, 0, 20)
@ -300,7 +300,7 @@ func (t *Tree) match(treePattern string, pattern string, wildcardValues []string
pattern = pattern[i:] pattern = pattern[i:]
} }
// Handle leaf nodes: // Handle leaf nodes:
if len(pattern) == 0 { if pattern == "" {
for _, l := range t.leaves { for _, l := range t.leaves {
if ok := l.match(treePattern, wildcardValues, ctx); ok { if ok := l.match(treePattern, wildcardValues, ctx); ok {
return l.runObject return l.runObject
@ -329,7 +329,7 @@ func (t *Tree) match(treePattern string, pattern string, wildcardValues []string
} }
for _, subTree := range t.fixrouters { for _, subTree := range t.fixrouters {
if subTree.prefix == seg { if subTree.prefix == seg {
if len(pattern) != 0 && pattern[0] == '/' { if pattern != "" && pattern[0] == '/' {
treePattern = pattern[1:] treePattern = pattern[1:]
} else { } else {
treePattern = pattern treePattern = pattern