mirror of https://github.com/hashicorp/consul
Makes UUID regex case-insensitive.
parent
e1ce1a34b0
commit
06b918e46d
|
@ -9,7 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// validUUID is used to check if a given string looks like a UUID
|
// 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.
|
// isUUID returns true if the given string is a valid UUID.
|
||||||
func isUUID(str string) bool {
|
func isUUID(str string) bool {
|
||||||
|
|
|
@ -13,9 +13,14 @@ func TestStateStore_PreparedQuery_isUUID(t *testing.T) {
|
||||||
"": false,
|
"": false,
|
||||||
"nope": false,
|
"nope": false,
|
||||||
"f004177f-2c28-83b7-4229-eacc25fe55d1": true,
|
"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, // Leading whitespace
|
||||||
"f004177f-2c28-83b7-4229-eacc25fe55d1 ": false, // Trailing whitespace
|
"f004177f-2c28-83b7-4229-eacc25fe55d1 ": false, // Trailing whitespace
|
||||||
"f004177f-2c28-83B7-4229-eacc25fe55d1": false, // Bad hex "83B7"
|
|
||||||
}
|
}
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
cases[testUUID()] = true
|
cases[testUUID()] = true
|
||||||
|
|
Loading…
Reference in New Issue