Skip to content

Commit 49abfd2

Browse files
committed
add : to valid map key names
Signed-off-by: Doug Davis <duglin@gmail.com>
1 parent 54d3feb commit 49abfd2

4 files changed

Lines changed: 9 additions & 5 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,3 @@ TODOs:
148148
- allow any model change, verify entities
149149
- make sure that maxversions=0 when we only support 1 means sitcky must be false
150150
- add "relaxednames" to attr aspects
151-
- add ":" to map key names

registry/model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
var RegexpModelName = regexp.MustCompile("^[a-z_][a-z_0-9]{0,57}$")
1818
var RegexpPropName = regexp.MustCompile("^[a-z_][a-z_0-9]{0,62}$")
19-
var RegexpMapKey = regexp.MustCompile("^[a-z0-9][a-z0-9_.\\-]{0,62}$")
19+
var RegexpMapKey = regexp.MustCompile("^[a-z0-9][a-z0-9_.:\\-]{0,62}$")
2020
var RegexpID = regexp.MustCompile("^[a-zA-Z0-9_][a-zA-Z0-9_.\\-~@]{0,127}$")
2121

2222
type ModelSerializer func(*Model, string) ([]byte, error)

registry/model_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ func TestValidChars(t *testing.T) {
739739
{"a*", `Invalid map key name "a*", must match: ` + match},
740740
{"a!", `Invalid map key name "a!", must match: ` + match},
741741
{"a~", `Invalid map key name "a~", must match: ` + match},
742+
{":a", `Invalid map key name ":a", must match: ` + match},
742743
{a64, `Invalid map key name "` + a64 + `", must match: ` + match},
743744

744745
{"a", ``},
@@ -752,6 +753,7 @@ func TestValidChars(t *testing.T) {
752753
{"m-z", ``},
753754
{"m.9", ``},
754755
{"m_9", ``},
756+
{"m:9", ``},
755757
{a63, ``},
756758
} {
757759
err := IsValidMapKey(test.input)

tests/set_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,15 +626,18 @@ func TestSetNameUser(t *testing.T) {
626626
}
627627
`)
628628

629+
xHTTP(t, reg, "PUT", "/", `{"mymap":{":bar":"bar"}}`, 400,
630+
`Invalid map key name ":bar", must match: ^[a-z0-9][a-z0-9_.:\-]{0,62}$
631+
`)
629632
xHTTP(t, reg, "PUT", "/", `{"mymap":{"@bar":"bar"}}`, 400,
630-
`Invalid map key name "@bar", must match: ^[a-z0-9][a-z0-9_.\-]{0,62}$
633+
`Invalid map key name "@bar", must match: ^[a-z0-9][a-z0-9_.:\-]{0,62}$
631634
`)
632635
// This is ok because "mymap" is under "ext" which is defined as "*"
633636
// and that allows ANYTHING as long as it's valid json
634637
xHTTP(t, reg, "PUT", "/", `{"ext":{"mymap":{"@bar":"bar"}}}`, 200, `*`)
635638

636639
xHTTP(t, reg, "PUT", "/dirs/d1", `{"mymap":{"@bar":"bar"}}`, 400,
637-
`Invalid map key name "@bar", must match: ^[a-z0-9][a-z0-9_.\-]{0,62}$
640+
`Invalid map key name "@bar", must match: ^[a-z0-9][a-z0-9_.:\-]{0,62}$
638641
`)
639642
// This is ok because "mymap" is under "ext" which is defined as "*"
640643
// and that allows ANYTHING as long as it's valid json
@@ -643,7 +646,7 @@ func TestSetNameUser(t *testing.T) {
643646

644647
xHTTP(t, reg, "PUT", "/dirs/d1/files/f1$details",
645648
`{"mymap":{"@bar":"bar"}}`, 400,
646-
`Invalid map key name "@bar", must match: ^[a-z0-9][a-z0-9_.\-]{0,62}$
649+
`Invalid map key name "@bar", must match: ^[a-z0-9][a-z0-9_.:\-]{0,62}$
647650
`)
648651
// This is ok because "mymap" is under "ext" which is defined as "*"
649652
// and that allows ANYTHING as long as it's valid json

0 commit comments

Comments
 (0)