From 4a689adbe98abe3de08dad6adfb8e5d0d685f4c8 Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 7 Apr 2016 13:59:29 +0200 Subject: [PATCH 1/2] Changed the HEX pattern. According to RFC and valid HEX characters, I suggest changing the word characters range to `a-f` only. Otherwise your previous pattern will match string like `zzzzzzzz-zzzz-1zzz-zzzz-zzzzzzzzzzzz` which is not a valid UUID. --- uuid.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uuid.go b/uuid.go index ac9623b..75ea70d 100644 --- a/uuid.go +++ b/uuid.go @@ -36,8 +36,8 @@ var ( // FIXME: do something to consider both brackets at one time, // current one allows to parse string with only one opening // or closing bracket. -const hexPattern = "^(urn\\:uuid\\:)?\\{?([a-z0-9]{8})-([a-z0-9]{4})-" + - "([1-5][a-z0-9]{3})-([a-z0-9]{4})-([a-z0-9]{12})\\}?$" +const hexPattern = "^(urn\\:uuid\\:)?\\{?([a-f0-9]{8})-([a-f0-9]{4})-" + + "([1-5][a-f0-9]{3})-([a-f0-9]{4})-([a-f0-9]{12})\\}?$" var re = regexp.MustCompile(hexPattern) From a1bd7c90b0b512bcb7a940402bd9bfd5e66044c7 Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 7 Apr 2016 14:01:02 +0200 Subject: [PATCH 2/2] Changed the format. According to suggested change in `uuid.go` I suggest the same range change in the test. --- uuid_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uuid_test.go b/uuid_test.go index 70ed346..2ec0775 100644 --- a/uuid_test.go +++ b/uuid_test.go @@ -10,7 +10,7 @@ import ( "testing" ) -const format = "^[a-z0-9]{8}-[a-z0-9]{4}-[1-5][a-z0-9]{3}-[a-z0-9]{4}-[a-z0-9]{12}$" +const format = "^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}$" func TestParse(t *testing.T) { _, err := Parse([]byte{1, 2, 3, 4, 5})