Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pgtype/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func (b UUID) UUIDValue() (UUID, error) {
func parseUUID(src string) (dst [16]byte, err error) {
switch len(src) {
case 36:
if src[8] != '-' || src[13] != '-' || src[18] != '-' || src[23] != '-' {
return dst, fmt.Errorf("cannot parse UUID %v", src)
}
src = src[0:8] + src[9:13] + src[14:18] + src[19:23] + src[24:]
case 32:
// dashes already stripped, assume valid
Expand Down
11 changes: 11 additions & 0 deletions pgtype/uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,14 @@ func TestUUID_UnmarshalJSON(t *testing.T) {
})
}
}

func TestUUIDRejectsMisplacedHyphens(t *testing.T) {
for _, s := range []string{
"a0eebc99X9c0bX4ef8Xbb6dX6bb9bd380a11",
"a0eebc999c0b4ef8bb6d6bb9bd380a11abcd",
} {
var u pgtype.UUID
require.Errorf(t, u.Scan(s), "Scan(%q)", s)
require.Errorf(t, u.UnmarshalJSON([]byte(`"`+s+`"`)), "UnmarshalJSON(%q)", s)
}
}