Skip to content

Commit

Permalink
make UUID regex case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskaly authored and johandorland committed Apr 24, 2020
1 parent b537c05 commit 065759f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion format_checkers.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ var (
// Use a regex to make sure curly brackets are balanced properly after validating it as a AURI
rxURITemplate = regexp.MustCompile("^([^{]*({[^}]*})?)*$")

rxUUID = regexp.MustCompile("^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$")
rxUUID = regexp.MustCompile("^(?i)[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$")

rxJSONPointer = regexp.MustCompile("^(?:/(?:[^~/]|~0|~1)*)*$")

Expand Down
5 changes: 4 additions & 1 deletion format_checkers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ package gojsonschema

import (
"encoding/json"
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestUUIDFormatCheckerIsFormat(t *testing.T) {
checker := UUIDFormatChecker{}

assert.True(t, checker.IsFormat("01234567-89ab-cdef-0123-456789abcdef"))
assert.True(t, checker.IsFormat("f1234567-89ab-cdef-0123-456789abcdef"))
assert.True(t, checker.IsFormat("01234567-89AB-CDEF-0123-456789ABCDEF"))
assert.True(t, checker.IsFormat("F1234567-89AB-CDEF-0123-456789ABCDEF"))

assert.False(t, checker.IsFormat("not-a-uuid"))
assert.False(t, checker.IsFormat("g1234567-89ab-cdef-0123-456789abcdef"))
Expand Down

0 comments on commit 065759f

Please sign in to comment.