Skip to content

Commit 06acd47

Browse files
committed
tweak ID chars
Signed-off-by: Doug Davis <[email protected]>
1 parent 387dda7 commit 06acd47

File tree

4 files changed

+35
-29
lines changed

4 files changed

+35
-29
lines changed

registry/model.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
var RegexpModelName = regexp.MustCompile("^[a-z_][a-z_0-9]{0,57}$")
1919
var RegexpPropName = regexp.MustCompile("^[a-z_][a-z_0-9]{0,62}$")
2020
var RegexpMapKey = regexp.MustCompile("^[a-z0-9][a-z0-9_.\\-]{0,62}$")
21-
var RegexpID = regexp.MustCompile("^[a-zA-Z0-9_.\\-~@]{1,128}$")
21+
var RegexpID = regexp.MustCompile("^[a-zA-Z0-9_][a-zA-Z0-9_.\\-~@]{0,127}$")
2222

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

registry/model_test.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -687,10 +687,6 @@ func TestValidChars(t *testing.T) {
687687
{"a", ``},
688688
{"A", ``},
689689
{"_", ``},
690-
{".", ``},
691-
{"-", ``},
692-
{"~", ``},
693-
{"@", ``},
694690
{"0", ``},
695691
{"9", ``},
696692
{"aa", ``},
@@ -700,6 +696,7 @@ func TestValidChars(t *testing.T) {
700696
{"a-", ``},
701697
{"a~", ``},
702698
{"a@", ``},
699+
{"a9", ``},
703700
{"9a", ``},
704701
{"9A", ``},
705702
{"9_", ``},
@@ -708,7 +705,14 @@ func TestValidChars(t *testing.T) {
708705
{"9~", ``},
709706
{"9@", ``},
710707
{"90", ``},
711-
{".-~_0Nb", ``},
708+
{"_Z", ``},
709+
{"_Z_", ``},
710+
{" a", `Invalid ID " a", must match: ` + match},
711+
{".", `Invalid ID ".", must match: ` + match},
712+
{"-", `Invalid ID "-", must match: ` + match},
713+
{"~", `Invalid ID "~", must match: ` + match},
714+
{"@", `Invalid ID "@", must match: ` + match},
715+
{"Z.-~_0Nb", ``},
712716
{a128, ``},
713717
} {
714718
err := IsValidID(test.input)

tests/http2_test.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -7610,38 +7610,40 @@ func TestHTTPInvalidID(t *testing.T) {
76107610
gm, _ := reg.Model.AddGroupModel("dirs", "dir")
76117611
gm.AddResourceModelSimple("files", "file")
76127612

7613+
match := `^[a-zA-Z0-9_][a-zA-Z0-9_.\-~@]{0,127}$`
7614+
76137615
xHTTP(t, reg, "PUT", "/", `{"registryid": "*" }`, 400,
7614-
`Invalid ID "*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`+"\n")
7616+
`Invalid ID "*", must match: `+match+"\n")
76157617

76167618
xHTTP(t, reg, "PUT", "/dirs/d1*", `{}`, 400,
7617-
`Invalid ID "d1*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`+"\n")
7619+
`Invalid ID "d1*", must match: `+match+"\n")
76187620
xHTTP(t, reg, "PUT", "/dirs/d1", `{"dirid": "d1*" }`, 400,
7619-
`Invalid ID "d1*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`+"\n")
7621+
`Invalid ID "d1*", must match: `+match+"\n")
76207622
xHTTP(t, reg, "POST", "/dirs/", `{"d1*":{}}`, 400,
7621-
`Invalid ID "d1*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`+"\n")
7623+
`Invalid ID "d1*", must match: `+match+"\n")
76227624
xHTTP(t, reg, "POST", "/dirs/", `{"d1*":{"dirid": "d1*" }}`, 400,
7623-
`Invalid ID "d1*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`+"\n")
7625+
`Invalid ID "d1*", must match: `+match+"\n")
76247626
xHTTP(t, reg, "POST", "/dirs/", `{"d1":{"dirid": "d2*" }}`, 400,
7625-
`Invalid ID "d2*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`+"\n")
7627+
`Invalid ID "d2*", must match: `+match+"\n")
76267628

76277629
xHTTP(t, reg, "PUT", "/dirs/d1/files/f1*$structure", `{}`, 400,
7628-
`Invalid ID "f1*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`+"\n")
7630+
`Invalid ID "f1*", must match: `+match+"\n")
76297631
xHTTP(t, reg, "PUT", "/dirs/d1/files/f1$structure", `{"fileid":"f1*"}`, 400,
76307632
"The \"fileid\" attribute must be set to \"f1\", not \"f1*\"\n")
76317633
xHTTP(t, reg, "PUT", "/dirs/d1/files/f1$structure", `{"versionid":"v1*"}`,
76327634
400,
7633-
`Invalid ID "v1*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`+"\n")
7635+
`Invalid ID "v1*", must match: `+match+"\n")
76347636

76357637
xHTTP(t, reg, "POST", "/dirs/d1/files/f1/versions", `{"v1*":{}}`, 400,
7636-
`Invalid ID "v1*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`+"\n")
7638+
`Invalid ID "v1*", must match: `+match+"\n")
76377639
xHTTP(t, reg, "PUT", "/dirs/d1/files/f1/versions/v1*", `{}`, 400,
7638-
`Invalid ID "v1*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`+"\n")
7640+
`Invalid ID "v1*", must match: `+match+"\n")
76397641
xHTTP(t, reg, "PUT", "/dirs/d1/files/f1/versions/v1$structure",
76407642
`{"versionid": "v1*"}`, 400,
7641-
`Invalid ID "v1*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`+"\n")
7643+
`Invalid ID "v1*", must match: `+match+"\n")
76427644
xHTTP(t, reg, "PUT", "/dirs/d1/files/f1/versions/v1$structure",
76437645
`{"fileid": "f1*"}`, 400,
7644-
`Invalid ID "f1*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`+"\n")
7646+
`Invalid ID "f1*", must match: `+match+"\n")
76457647
}
76467648

76477649
func TestHTTPSpecVersion(t *testing.T) {

tests/types_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func TestBasicTypes(t *testing.T) {
153153
tests := []Test{
154154
Test{reg, []Prop{
155155
{"registryid", 66, nil, `Attribute "registryid" must be a string`},
156-
{"registryid", "*", nil, `Invalid ID "*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`},
156+
{"registryid", "*", nil, `Invalid ID "*", must match: ^[a-zA-Z0-9_][a-zA-Z0-9_.\-~@]{0,127}$`},
157157

158158
{"regarrayarrayint[1][1]", 66, nil, "Attribute \"regarrayarrayint[1][0]\" must be an integer"},
159159
{"regarrayint[0]", 1, nil, ""},
@@ -250,7 +250,7 @@ func TestBasicTypes(t *testing.T) {
250250
{"regptr_group", "/dirs", nil, `Attribute "regptr_group" must match "/dirs" target, missing "dirid"`},
251251
{"regptr_group", "/dirs2", nil, `Attribute "regptr_group" must match "/dirs" target`},
252252
{"regptr_group", "/dirs", nil, `Attribute "regptr_group" must match "/dirs" target, missing "dirid"`},
253-
{"regptr_group", "/dirs/*", nil, `Attribute "regptr_group" must match "/dirs" target: Invalid ID "*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`},
253+
{"regptr_group", "/dirs/*", nil, `Attribute "regptr_group" must match "/dirs" target: Invalid ID "*", must match: ^[a-zA-Z0-9_][a-zA-Z0-9_.\-~@]{0,127}$`},
254254
{"regptr_group", "/dirs/id/", nil, `Attribute "regptr_group" must match "/dirs" target, extra stuff after "id"`},
255255
{"regptr_group", "/dirs/id/extra", nil, `Attribute "regptr_group" must match "/dirs" target, extra stuff after "id"`},
256256
{"regptr_group", "/dirs/id/extra/", nil, `Attribute "regptr_group" must match "/dirs" target, extra stuff after "id"`},
@@ -261,10 +261,10 @@ func TestBasicTypes(t *testing.T) {
261261
{"regptr_res", "/dirs/d1/fff", nil, `Attribute "regptr_res" must match "/dirs/files" target, missing "files"`},
262262
{"regptr_res", "/dirs/d1/fff/", nil, `Attribute "regptr_res" must match "/dirs/files" target, missing "files"`},
263263
{"regptr_res", "/dirs/d1/fff/f2", nil, `Attribute "regptr_res" must match "/dirs/files" target, missing "files"`},
264-
{"regptr_res", "/dirs/*/files/f2", nil, `Attribute "regptr_res" must match "/dirs/files" target: Invalid ID "*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`},
264+
{"regptr_res", "/dirs/*/files/f2", nil, `Attribute "regptr_res" must match "/dirs/files" target: Invalid ID "*", must match: ^[a-zA-Z0-9_][a-zA-Z0-9_.\-~@]{0,127}$`},
265265
{"regptr_res", "/dirs/d1/files", nil, `Attribute "regptr_res" must match "/dirs/files" target, missing "fileid"`},
266266
{"regptr_res", "/dirs/d1/files/", nil, `Attribute "regptr_res" must match "/dirs/files" target, missing "fileid"`},
267-
{"regptr_res", "/dirs/d1/files/*", nil, `Attribute "regptr_res" must match "/dirs/files" target: Invalid ID "*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`},
267+
{"regptr_res", "/dirs/d1/files/*", nil, `Attribute "regptr_res" must match "/dirs/files" target: Invalid ID "*", must match: ^[a-zA-Z0-9_][a-zA-Z0-9_.\-~@]{0,127}$`},
268268
{"regptr_res", "/dirs/d1/files/f2/versions", nil, `Attribute "regptr_res" must match "/dirs/files" target, extra stuff after "f2"`},
269269
{"regptr_res", "/dirs/d1/files/f2/versions/v1", nil, `Attribute "regptr_res" must match "/dirs/files" target, extra stuff after "f2"`},
270270
{"regptr_res", "/dirs/d1/files/f2", nil, ``},
@@ -276,27 +276,27 @@ func TestBasicTypes(t *testing.T) {
276276
{"regptr_ver", "/dirs/d1/files/f2/versions/", nil, `Attribute "regptr_ver" must match "/dirs/files/versions" target, missing a "versionid"`},
277277
{"regptr_ver", "/dirs/d1/files/f2/versions/v2/", nil, `Attribute "regptr_ver" must match "/dirs/files/versions" target, too long`},
278278
{"regptr_ver", "/dirs/d1/files/f2/versions/v2/xx", nil, `Attribute "regptr_ver" must match "/dirs/files/versions" target, too long`},
279-
{"regptr_ver", "/dirs/d1/files/f2/versions/v2?", nil, `Attribute "regptr_ver" must match "/dirs/files/versions" target: Invalid ID "v2?", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`},
279+
{"regptr_ver", "/dirs/d1/files/f2/versions/v2?", nil, `Attribute "regptr_ver" must match "/dirs/files/versions" target: Invalid ID "v2?", must match: ^[a-zA-Z0-9_][a-zA-Z0-9_.\-~@]{0,127}$`},
280280
{"regptr_ver", "/dirs/d1/files/f2/versions/v2", nil, ``},
281281

282282
{"regptr_res_ver", "/dirs/d1/files/", nil, `Attribute "regptr_res_ver" must match "/dirs/files[/versions]" target, missing "fileid"`},
283283
{"regptr_res_ver", "/dirs/d1/files//", nil, `Attribute "regptr_res_ver" must match "/dirs/files[/versions]" target, missing "fileid"`},
284284
{"regptr_res_ver", "/dirs/d1/files/f2/", nil, `Attribute "regptr_res_ver" must match "/dirs/files[/versions]" target, missing "versions"`},
285285
{"regptr_res_ver", "/dirs/d1/files/f2/vers", nil, `Attribute "regptr_res_ver" must match "/dirs/files[/versions]" target, missing "versions"`},
286286
{"regptr_res_ver", "/dirs/d1/files/f2/vers/v1", nil, `Attribute "regptr_res_ver" must match "/dirs/files[/versions]" target, missing "versions"`},
287-
{"regptr_res_ver", "/dirs/d1/files/f*/vers/v1", nil, `Attribute "regptr_res_ver" must match "/dirs/files[/versions]" target: Invalid ID "f*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`},
287+
{"regptr_res_ver", "/dirs/d1/files/f*/vers/v1", nil, `Attribute "regptr_res_ver" must match "/dirs/files[/versions]" target: Invalid ID "f*", must match: ^[a-zA-Z0-9_][a-zA-Z0-9_.\-~@]{0,127}$`},
288288
{"regptr_res_ver", "/dirs/d1/files/f2", nil, ``},
289289

290290
{"regptr_res_ver2", "/dirs/d1/files/f2/versions", nil, `Attribute "regptr_res_ver2" must match "/dirs/files[/versions]" target, missing a "versionid"`},
291291
{"regptr_res_ver2", "/dirs/d1/files/f2/versions/", nil, `Attribute "regptr_res_ver2" must match "/dirs/files[/versions]" target, missing a "versionid"`},
292292
{"regptr_res_ver2", "/dirs/d1/files/f2/versions//v2", nil, `Attribute "regptr_res_ver2" must match "/dirs/files[/versions]" target, missing a "versionid"`},
293293
{"regptr_res_ver2", "/dirs/d1/files/f2/versions/v2/", nil, `Attribute "regptr_res_ver2" must match "/dirs/files[/versions]" target, too long`},
294-
{"regptr_res_ver2", "/dirs/d1/files/f2/versions/v*", nil, `Attribute "regptr_res_ver2" must match "/dirs/files[/versions]" target: Invalid ID "v*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`},
294+
{"regptr_res_ver2", "/dirs/d1/files/f2/versions/v*", nil, `Attribute "regptr_res_ver2" must match "/dirs/files[/versions]" target: Invalid ID "v*", must match: ^[a-zA-Z0-9_][a-zA-Z0-9_.\-~@]{0,127}$`},
295295
{"regptr_res_ver2", "/dirs/d1/files/f2/versions/v2", nil, ``},
296296
}},
297297
Test{dir, []Prop{
298298
{"dirid", 66, nil, `Attribute "dirid" must be a string`},
299-
{"dirid", "*", nil, `Invalid ID "*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`},
299+
{"dirid", "*", nil, `Invalid ID "*", must match: ^[a-zA-Z0-9_][a-zA-Z0-9_.\-~@]{0,127}$`},
300300

301301
{"dirstring1", "str2", nil, ""},
302302
{"dirstring2", "", nil, ""},
@@ -320,9 +320,9 @@ func TestBasicTypes(t *testing.T) {
320320
}},
321321
Test{file, []Prop{
322322
{"fileid", 66, nil, `Attribute "fileid" must be a string`},
323-
{"fileid", "*", nil, `Invalid ID "*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`},
323+
{"fileid", "*", nil, `Invalid ID "*", must match: ^[a-zA-Z0-9_][a-zA-Z0-9_.\-~@]{0,127}$`},
324324
{"versionid", 66, nil, `Attribute "versionid" must be a string`},
325-
{"versionid", "*", nil, `Invalid ID "*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`},
325+
{"versionid", "*", nil, `Invalid ID "*", must match: ^[a-zA-Z0-9_][a-zA-Z0-9_.\-~@]{0,127}$`},
326326

327327
{"filestring1", "str3", nil, ""},
328328
{"filestring2", "", nil, ""},
@@ -338,7 +338,7 @@ func TestBasicTypes(t *testing.T) {
338338
}},
339339
Test{ver, []Prop{
340340
{"versionid", 66, nil, `Attribute "versionid" must be a string`},
341-
{"versionid", "*", nil, `Invalid ID "*", must match: ^[a-zA-Z0-9_.\-~@]{1,128}$`},
341+
{"versionid", "*", nil, `Invalid ID "*", must match: ^[a-zA-Z0-9_][a-zA-Z0-9_.\-~@]{0,127}$`},
342342

343343
{"filestring1", "str4", nil, ""},
344344
{"filestring2", "", nil, ""},

0 commit comments

Comments
 (0)