Skip to content

Commit

Permalink
Add tests for some bad input (serialization structures)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbetz committed Oct 18, 2017
1 parent 3cce2d7 commit a746956
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion search-replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const (
searchRe = `s:\d+:\\?\".*?\\?\";`
replaceRe = `(?:s:)(?:\d+:)(\\?\")(.*?)(\\?\";)`

inputRe = `^[A-Za-z0-9\-\.:/]{4,}$`
inputRe = `^[A-Za-z0-9\-\.:/]{4,}$`
badInputRe = `\w:\d+:`
)

var (
Expand Down Expand Up @@ -120,5 +121,10 @@ func validInput(in string) bool {
return false
}

bad := regexp.MustCompile(badInputRe)
if bad.MatchString(in) {
return false
}

return true
}
15 changes: 15 additions & 0 deletions search-replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,21 @@ func TestInput(t *testing.T) {
in: "automattic.com",
valid: true,
},
{
testName: "Short string",
in: "s:",
valid: false,
},
{
testName: "SQL string",
in: "),(",
valid: false,
},
{
testName: "Serialization structure",
in: "a:4:",
valid: false,
},
}

for _, test := range tests {
Expand Down

0 comments on commit a746956

Please sign in to comment.