Commit a1429e14 authored by Yong Tang's avatar Yong Tang Committed by GitHub

[plugin/rewrite] Refactor to satisfy security scan (#5214)

this PR re-arrange the logic to avoid a false positive DAST scan.
Signed-off-by: default avatarYong Tang <yong.tang.github@outlook.com>
parent 6c26446b
...@@ -298,18 +298,19 @@ func newNameRule(nextAction string, args ...string) (Rule, error) { ...@@ -298,18 +298,19 @@ func newNameRule(nextAction string, args ...string) (Rule, error) {
return nil, fmt.Errorf("too few arguments for a name rule") return nil, fmt.Errorf("too few arguments for a name rule")
} }
if len(args) == 2 { if len(args) == 2 {
matchType = "exact" matchType = ExactMatch
rewriteQuestionFrom = plugin.Name(args[0]).Normalize() rewriteQuestionFrom = plugin.Name(args[0]).Normalize()
rewriteQuestionTo = plugin.Name(args[1]).Normalize() rewriteQuestionTo = plugin.Name(args[1]).Normalize()
} }
if len(args) >= 3 { if len(args) >= 3 {
matchType = strings.ToLower(args[0]) matchType = strings.ToLower(args[0])
rewriteQuestionFrom = plugin.Name(args[1]).Normalize() if matchType == RegexMatch {
rewriteQuestionTo = plugin.Name(args[2]).Normalize() rewriteQuestionFrom = args[1]
} rewriteQuestionTo = args[2]
if matchType == RegexMatch { } else {
rewriteQuestionFrom = args[1] rewriteQuestionFrom = plugin.Name(args[1]).Normalize()
rewriteQuestionTo = args[2] rewriteQuestionTo = plugin.Name(args[2]).Normalize()
}
} }
if matchType == ExactMatch || matchType == SuffixMatch { if matchType == ExactMatch || matchType == SuffixMatch {
if !hasClosingDot(rewriteQuestionFrom) { if !hasClosingDot(rewriteQuestionFrom) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment