Skip to content

Commit

Permalink
Fixed bug with Detect line does not work for OpenAPI template path #3386
Browse files Browse the repository at this point in the history


Signed-off-by: João Reigota <[email protected]>
  • Loading branch information
joaoReigota1 committed May 20, 2021
1 parent 7b4aaff commit 0e6f892
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{
"queryName": "Parameter Object With Undefined Type",
"severity": "INFO",
"line": 7,
"line": 55,
"filename": "positive1.json"
},
{
Expand All @@ -20,7 +20,7 @@
{
"queryName": "Parameter Object With Undefined Type",
"severity": "INFO",
"line": 5,
"line": 40,
"filename": "positive2.yaml"
},
{
Expand Down
4 changes: 4 additions & 0 deletions pkg/detector/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func GetBracketValues(expr string, list [][]string, restOfString string) [][]str
var tempList []string
firstOpen := strings.Index(expr, "{{")
firstClose := strings.Index(expr, "}}")
// in case we have '}}}' we need to advance one position to get the close
for firstClose+2 < len(expr) && string(expr[firstClose+2]) == `}` && firstClose != -1 {
firstClose++
}
switchVal := firstClose - firstOpen
if switchVal == 0 { // if there is no "{{" and no "}}"
if expr != "" {
Expand Down
12 changes: 12 additions & 0 deletions pkg/detector/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ func TestGetBracketValues(t *testing.T) {
},
},
},
{
name: "single_brackets",
args: args{
expr: "paths.{{user/{id}}}",
},
want: [][]string{
{
"{{user/{id}}}",
"user/{id}",
},
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 0e6f892

Please sign in to comment.