Skip to content

Commit

Permalink
consumer: allow PathSymbols in shard IDs
Browse files Browse the repository at this point in the history
Updates consumer shard ID validation to permit a few additional symbols,
and bring the set of allowable characters in line with journal names.
The characters "=%:" were previously disallowed in shard IDs, but
allowed in journal names and label values. Those characters are now
permissible in shard IDs too.
  • Loading branch information
psFried committed Jun 17, 2024
1 parent f28f519 commit edf95ee
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
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
6 changes: 3 additions & 3 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.
// PathSymbols is allowed runes of strings which form path components.
// It extends TokenSymbols with the '=', '%', and ':' runes.
pathSymbols = TokenSymbols + "=%:"
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

0 comments on commit edf95ee

Please sign in to comment.