From a2e0251f86dfde4c5d5fdfed794e95a00c6f03c0 Mon Sep 17 00:00:00 2001 From: Tomasz Pietrek Date: Thu, 25 Jul 2024 11:33:22 +0200 Subject: [PATCH] Improve subject validation Signed-off-by: Tomasz Pietrek --- async-nats/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/async-nats/src/lib.rs b/async-nats/src/lib.rs index f6e20a527..a530d63a5 100755 --- a/async-nats/src/lib.rs +++ b/async-nats/src/lib.rs @@ -1555,9 +1555,11 @@ impl ToServerAddrs for &T { } pub(crate) fn is_valid_subject>(subject: T) -> bool { - !subject.as_ref().contains([' ', '.', '\r', '\n']) + let subject_str = subject.as_ref(); + !subject_str.starts_with('.') + && !subject_str.ends_with('.') + && subject_str.bytes().all(|c| !c.is_ascii_whitespace()) } - macro_rules! from_with_timeout { ($t:ty, $k:ty, $origin: ty, $origin_kind: ty) => { impl From<$origin> for $t {