File tree Expand file tree Collapse file tree 3 files changed +12
-5
lines changed Expand file tree Collapse file tree 3 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -80,10 +80,10 @@ var (
80
80
// ErrNotJSMessage is returned when attempting to get metadata from non JetStream message .
81
81
ErrNotJSMessage JetStreamError = & jsError {message : "not a jetstream message" }
82
82
83
- // ErrInvalidStreamName is returned when the provided stream name is invalid (contains '.').
83
+ // ErrInvalidStreamName is returned when the provided stream name is invalid (contains '.' or ' ' ).
84
84
ErrInvalidStreamName JetStreamError = & jsError {message : "invalid stream name" }
85
85
86
- // ErrInvalidConsumerName is returned when the provided consumer name is invalid (contains '.').
86
+ // ErrInvalidConsumerName is returned when the provided consumer name is invalid (contains '.' or ' ' ).
87
87
ErrInvalidConsumerName JetStreamError = & jsError {message : "invalid consumer name" }
88
88
89
89
// ErrNoMatchingStream is returned when stream lookup by subject is unsuccessful.
Original file line number Diff line number Diff line change @@ -421,19 +421,20 @@ func checkStreamName(stream string) error {
421
421
if stream == _EMPTY_ {
422
422
return ErrStreamNameRequired
423
423
}
424
- if strings .Contains (stream , "." ) {
424
+ if strings .ContainsAny (stream , ". " ) {
425
425
return ErrInvalidStreamName
426
426
}
427
427
return nil
428
428
}
429
429
430
- // Check that the durable name exists and is valid, that is, that it does not contain any "."
430
+ // Check that the consumer name is not empty and is valid (does not contain "." and " ").
431
+ // Additional consumer name validation is done in nats-server.
431
432
// Returns ErrConsumerNameRequired if consumer name is empty, ErrInvalidConsumerName is invalid, otherwise nil
432
433
func checkConsumerName (consumer string ) error {
433
434
if consumer == _EMPTY_ {
434
435
return ErrConsumerNameRequired
435
436
}
436
- if strings .Contains (consumer , "." ) {
437
+ if strings .ContainsAny (consumer , ". " ) {
437
438
return ErrInvalidConsumerName
438
439
}
439
440
return nil
Original file line number Diff line number Diff line change @@ -1781,6 +1781,9 @@ func TestJetStreamManagement(t *testing.T) {
1781
1781
if _ , err := js .AddStream (& nats.StreamConfig {Name : "bad.stream.name" }); err != nats .ErrInvalidStreamName {
1782
1782
t .Fatalf ("Expected %v, got %v" , nats .ErrInvalidStreamName , err )
1783
1783
}
1784
+ if _ , err := js .AddStream (& nats.StreamConfig {Name : "bad stream name" }); err != nats .ErrInvalidStreamName {
1785
+ t .Fatalf ("Expected %v, got %v" , nats .ErrInvalidStreamName , err )
1786
+ }
1784
1787
})
1785
1788
1786
1789
t .Run ("bad stream info" , func (t * testing.T ) {
@@ -1956,6 +1959,9 @@ func TestJetStreamManagement(t *testing.T) {
1956
1959
if _ , err = js .AddConsumer ("foo" , & nats.ConsumerConfig {Durable : "test.durable" }); err != nats .ErrInvalidConsumerName {
1957
1960
t .Fatalf ("Expected: %v; got: %v" , nats .ErrInvalidConsumerName , err )
1958
1961
}
1962
+ if _ , err = js .AddConsumer ("foo" , & nats.ConsumerConfig {Durable : "test durable" }); err != nats .ErrInvalidConsumerName {
1963
+ t .Fatalf ("Expected: %v; got: %v" , nats .ErrInvalidConsumerName , err )
1964
+ }
1959
1965
})
1960
1966
1961
1967
t .Run ("consumer with given name already exists, configs do not match" , func (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments