Skip to content

Commit 7575c2f

Browse files
authored
Merge pull request #50 from linuxfoundation/jme/LFXV2-1652
fix: allow underscores in parent field type fragment (LFXV2-1652)
2 parents 43b083b + 267d883 commit 7575c2f

8 files changed

Lines changed: 61 additions & 7 deletions

File tree

cmd/service/parent_regex_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright The Linux Foundation and each contributor to LFX.
2+
// SPDX-License-Identifier: MIT
3+
4+
package service
5+
6+
import (
7+
"regexp"
8+
"testing"
9+
)
10+
11+
// parentPattern mirrors the Goa design pattern at design/query-svc.go.
12+
// This test exists to guard against accidental regex regression.
13+
const parentPattern = `^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$`
14+
15+
func TestParentPattern(t *testing.T) {
16+
re := regexp.MustCompile(parentPattern)
17+
18+
valid := []string{
19+
"project:123",
20+
"past_meeting:98471391296-1765832400000",
21+
"v1_meeting:abc-123",
22+
"v1_past_meeting:foo_bar-baz",
23+
"committee:abc",
24+
}
25+
for _, v := range valid {
26+
if !re.MatchString(v) {
27+
t.Errorf("expected %q to match parent pattern", v)
28+
}
29+
}
30+
31+
invalid := []string{
32+
"past_meeting:", // empty id fragment
33+
":abc", // empty type fragment
34+
"_leading:abc", // leading underscore in type
35+
"past meeting:abc", // space in type
36+
"project", // missing colon
37+
"", // empty
38+
}
39+
for _, v := range invalid {
40+
if re.MatchString(v) {
41+
t.Errorf("expected %q to NOT match parent pattern", v)
42+
}
43+
}
44+
}

design/query-svc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var _ = dsl.Service("query-svc", func() {
4545
})
4646
dsl.Attribute("parent", dsl.String, "Parent (for navigation; varies by object type)", func() {
4747
dsl.Example("project:123")
48-
dsl.Pattern(`^[a-zA-Z]+:[a-zA-Z0-9_-]+$`)
48+
dsl.Pattern(`^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$`)
4949
})
5050
dsl.Attribute("type", dsl.String, "Resource type to search", func() {
5151
dsl.Example("committee")
@@ -145,6 +145,7 @@ var _ = dsl.Service("query-svc", func() {
145145
})
146146
dsl.Attribute("parent", dsl.String, "Parent (for navigation; varies by object type)", func() {
147147
dsl.Example("project:123")
148+
dsl.Pattern(`^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$`)
148149
})
149150
dsl.Attribute("type", dsl.String, "Resource type to search", func() {
150151
dsl.Example("committee")

gen/http/openapi.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

gen/http/openapi.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ paths:
159159
description: Parent (for navigation; varies by object type)
160160
required: false
161161
type: string
162-
pattern: ^[a-zA-Z]+:[a-zA-Z0-9_-]+$
162+
pattern: ^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$
163163
- name: type
164164
in: query
165165
description: Resource type to search
@@ -322,6 +322,7 @@ paths:
322322
description: Parent (for navigation; varies by object type)
323323
required: false
324324
type: string
325+
pattern: ^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$
325326
- name: type
326327
in: query
327328
description: Resource type to search

gen/http/openapi3.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

gen/http/openapi3.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ paths:
207207
type: string
208208
description: Parent (for navigation; varies by object type)
209209
example: project:123
210-
pattern: ^[a-zA-Z]+:[a-zA-Z0-9_-]+$
210+
pattern: ^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$
211211
example: project:123
212212
- name: type
213213
in: query
@@ -484,6 +484,7 @@ paths:
484484
type: string
485485
description: Parent (for navigation; varies by object type)
486486
example: project:123
487+
pattern: ^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$
487488
example: project:123
488489
- name: type
489490
in: query

gen/http/query_svc/client/cli.go

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/http/query_svc/server/encode_decode.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)