diff --git a/consul/state/prepared_query.go b/consul/state/prepared_query.go index b404977e3c..68a94524ca 100644 --- a/consul/state/prepared_query.go +++ b/consul/state/prepared_query.go @@ -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 { diff --git a/consul/state/prepared_query_test.go b/consul/state/prepared_query_test.go index 7f7dd0b7af..49817882ff 100644 --- a/consul/state/prepared_query_test.go +++ b/consul/state/prepared_query_test.go @@ -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