Skip to content

Commit e4050d2

Browse files
authored
fix literal regexp in http template (#124)
1 parent 2fc6a7a commit e4050d2

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

rules/aep0127/http_template_syntax.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
)
2626

2727
var (
28-
literal = `(\w+)`
28+
literal = `([a-z]([a-z0-9\-_]*[a-z0-9])?)`
2929
identifier = `(\w+)`
3030
verb = fmt.Sprintf("(:%s)", literal)
3131
fieldPath = fmt.Sprintf(`(%s(\.%s)*)`, identifier, identifier)

rules/aep0127/http_template_syntax_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func TestHttpTemplateSyntax(t *testing.T) {
3535
{"VersionedTemplate", "/{$api_version}/books", true},
3636
{"TwoLiterals", "/v1/books", true},
3737
{"ThreeLiterals", "/v1/books/shelves", true},
38+
{"KebabCaseLiteral", "/user-events", true},
3839
{"SingleLiteralWithVerb", "/v1:verb", true},
3940
{"MultipleLiteralsWithVerb", "/v1/books:verb", true},
4041
{"SingleWildcard", "/v1/*", true},
@@ -55,6 +56,7 @@ func TestHttpTemplateSyntax(t *testing.T) {
5556
{"VariableWithDoubleWildcardFollowedByLiteral", "/v1/{field=**/books}", true},
5657
{"VariableWithLiteralFollowedBySingleWildcard", "/v1/{field=books/*}", true},
5758
{"VariableWithLiteralFollowedByDoubleWildcard", "/v1/{field=books/**}", true},
59+
{"VariableWithKebabCaseLiteralFollowedBySingleWildcard", "/v1/{field=user-events/*}", true},
5860
{"VariableFollowedByLiteral", "/v1/{field}/books", true},
5961
{"VariableFollowedByVariable", "/v1/{field}/{otherField}", true},
6062
{"VariableWithTemplateFollowedByLiteral", "/v1/{field=books/*}/shelves", true},
@@ -64,7 +66,6 @@ func TestHttpTemplateSyntax(t *testing.T) {
6466
// Invalid cases
6567
{"LiteralWithoutLeadingSlash", "v1", false},
6668
{"LiteralFollowedBySlash", "/v1/", false},
67-
{"WrongVerbDelimiter", "/v1-verb", false},
6869
{"MultipleVerbs", "/v1:verb:verb", false},
6970
{"VerbFollowedBySlash", "/v1:verb/", false},
7071
{"MultipleLiteralsWithWrongDelimiter", "/v1|books", false},

0 commit comments

Comments
 (0)