Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phil/colons in names #386

Merged
merged 2 commits into from
Jun 17, 2024
Merged
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
1 change: 1 addition & 0 deletions broker/protocol/journal_spec_extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func (s *JournalSuite) TestJournalValidationCases(c *gc.C) {
expect string
}{
{"a/valid/path/to/a/journal", ""}, // Success.
{"a/valid/path/to/a:journal", ""}, // Success.
{"/leading/slash", `cannot begin with '/' \(/leading/slash\)`},
{"trailing/slash/", `must be a clean path \(trailing/slash/\)`},
{"extra-middle//slash", `must be a clean path \(extra-middle//slash\)`},
Expand Down
4 changes: 2 additions & 2 deletions broker/protocol/label_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func (m Label) Validate() error {
if err := ValidateToken(m.Name, TokenSymbols, minLabelLen, maxLabelLen); err != nil {
return ExtendContext(err, "Name")
} else if err = ValidateToken(m.Value, pathSymbols, 0, maxLabelValueLen); err != nil {
} else if err = ValidateToken(m.Value, PathSymbols, 0, maxLabelValueLen); err != nil {
return ExtendContext(err, "Value")
}
return nil
Expand Down Expand Up @@ -452,7 +452,7 @@ func parseSetParts(name, s string) ([]Label, error) {

var (
reToken = ` ?([\pL\pN\` + regexp.QuoteMeta(TokenSymbols) + `]{2,})`
rePath = ` ?([\pL\pN\` + regexp.QuoteMeta(pathSymbols) + `]{0,})`
rePath = ` ?([\pL\pN\` + regexp.QuoteMeta(PathSymbols) + `]{0,})`
reCommaOrEnd = ` ?(?:,|$)`
reParenthetical = ` ?\(([^)]+)\)`

Expand Down
2 changes: 2 additions & 0 deletions broker/protocol/label_extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ func (s *LabelSuite) TestLabelValidationCases(c *gc.C) {
}{
{"a-label", "a-value", ""}, // Success.
{"a/label", "a%20value", ""}, // Success.
{"a-label", "a:value", ""}, // Success
{"a|label", "a-value", `Name: not a valid token \(a|label\)`},
{"a-label", "a|value", `Value: not a valid token \(a|value\)`},
{"a:label", "a-value", `Name: not a valid token \(a:label\)`},
{"a", "a-value", `Name: invalid length \(1; expected 2 <= length <= 64\)`},
{strings.Repeat("a", maxLabelLen+1), "a-value", `Name: invalid length \(65; expected .*`},
{"a-label", "", ""}, // Success
Expand Down
8 changes: 4 additions & 4 deletions broker/protocol/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func ValidateToken(n, symbols string, min, max int) error {
// a "clean" path (as defined by path.Clean), is non-rooted, and consists only
// of characters drawn from pathSymbols.
func ValidatePathComponent(n string, min, max int) error {
if err := ValidateToken(n, pathSymbols, min, max); err != nil {
if err := ValidateToken(n, PathSymbols, min, max); err != nil {
return err
} else if n != "" && path.Clean(n) != n {
return NewValidationError("must be a clean path (%s)", n)
Expand All @@ -85,7 +85,7 @@ const (
// which is the allocator KeySpace separator, must not be included in this alphabet.
// The alphabet leads with '-' to facilitate escaping in |reToken|.
TokenSymbols = "-_+/."
// pathSymbols is allowed runes of strings which form path components.
// It extends TokenSymbols with the '=' and '%' runes.
pathSymbols = TokenSymbols + "=%"
// PathSymbols is allowed runes of strings which form path components.
// It extends TokenSymbols with the '=', '%', and ':' runes.
PathSymbols = TokenSymbols + "=%:"
)
2 changes: 1 addition & 1 deletion consumer/protocol/shard_spec_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewRoutedShardClient(sc ShardClient, dr pb.DispatchRouter) RoutedShardClien

// Validate returns an error if the Shard is not well-formed.
func (id ShardID) Validate() error {
if err := pb.ValidateToken(id.String(), pb.TokenSymbols, minShardNameLen, maxShardNameLen); err != nil {
if err := pb.ValidateToken(id.String(), pb.PathSymbols, minShardNameLen, maxShardNameLen); err != nil {
return err
}
return nil
Expand Down
1 change: 1 addition & 0 deletions consumer/protocol/shard_spec_extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func (s *SpecSuite) TestShardValidationCases(c *gc.C) {
expect string
}{
{"a-valid-shard", ""}, // Success.
{"a:valid-shard", ""}, // Success.
{"not-$%|-a-token", `not a valid token \(.*\)`},
{"", `invalid length \(0; expected 4 <= .*`},
{"zz", `invalid length \(2; expected 4 <= .*`},
Expand Down
Loading