Sniper template parsing - fixes #579 (#580)

* Add sniper template error cases to tests

* move injectKeyword to a seperate output slice - Fixes #579
This commit is contained in:
DoI 2023-02-03 03:01:07 +13:00 committed by GitHub
parent 9bddff79b9
commit ebb4c44072
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View File

@ -172,10 +172,12 @@ func injectKeyword(input string, keyword string, startOffset int, endOffset int)
prefix := inputslice[:startOffset]
suffix := inputslice[endOffset+1:]
inputslice = append(prefix, keywordslice...)
inputslice = append(inputslice, suffix...)
var outputslice []rune
outputslice = append(outputslice, prefix...)
outputslice = append(outputslice, keywordslice...)
outputslice = append(outputslice, suffix...)
return string(inputslice)
return string(outputslice)
}
// scrubTemplates removes all template (§) strings from the request struct

View File

@ -215,6 +215,23 @@ func TestInjectKeyword(t *testing.T) {
t.Errorf("injectKeyword offset validation failed")
}
input = "id=§a§&sort=desc"
offsetTuple = templateLocations("§", input)
expected = "id=FUZZ&sort=desc"
result = injectKeyword(input, "FUZZ", offsetTuple[0], offsetTuple[1])
if result != expected {
t.Errorf("injectKeyword returned unexpected result: " + result)
}
input = "feature=aaa&thingie=bbb&array[§0§]=baz"
offsetTuple = templateLocations("§", input)
expected = "feature=aaa&thingie=bbb&array[FUZZ]=baz"
result = injectKeyword(input, "FUZZ", offsetTuple[0], offsetTuple[1])
if result != expected {
t.Errorf("injectKeyword returned unexpected result: " + result)
}
}
func TestScrubTemplates(t *testing.T) {