Makes UUID regex case-insensitive.

This commit is contained in:
James Phillips 2015-11-16 22:57:47 -08:00
parent a1e02996e5
commit f4943c1613
2 changed files with 7 additions and 2 deletions

View file

@ -9,7 +9,7 @@ import (
)
// validUUID is used to check if a given string looks like a UUID
var validUUID = regexp.MustCompile(`^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$`)
var validUUID = regexp.MustCompile(`(?i)^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$`)
// isUUID returns true if the given string is a valid UUID.
func isUUID(str string) bool {

View file

@ -13,9 +13,14 @@ func TestStateStore_PreparedQuery_isUUID(t *testing.T) {
"": false,
"nope": false,
"f004177f-2c28-83b7-4229-eacc25fe55d1": true,
"F004177F-2C28-83B7-4229-EACC25FE55D1": true,
"x004177f-2c28-83b7-4229-eacc25fe55d1": false, // Bad hex
"f004177f-xc28-83b7-4229-eacc25fe55d1": false, // Bad hex
"f004177f-2c28-x3b7-4229-eacc25fe55d1": false, // Bad hex
"f004177f-2c28-83b7-x229-eacc25fe55d1": false, // Bad hex
"f004177f-2c28-83b7-4229-xacc25fe55d1": false, // Bad hex
" f004177f-2c28-83b7-4229-eacc25fe55d1": false, // Leading whitespace
"f004177f-2c28-83b7-4229-eacc25fe55d1 ": false, // Trailing whitespace
"f004177f-2c28-83B7-4229-eacc25fe55d1": false, // Bad hex "83B7"
}
for i := 0; i < 100; i++ {
cases[testUUID()] = true