notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 22f9c3212185d394ed5b34faf7c0205024d837f2
parent fe7f0a39766237308232dd740b5c205166c7f9e0
Author: Ken Sedgwick <ken@bonsai.com>
Date:   Thu, 20 Feb 2025 12:51:16 -0800

fix EOSE parsing to handle extra whitespace

Diffstat:
Mcrates/enostr/src/relay/message.rs | 19+++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/crates/enostr/src/relay/message.rs b/crates/enostr/src/relay/message.rs @@ -111,12 +111,23 @@ impl<'a> RelayMessage<'a> { // Relay response format: ["EOSE", <subscription_id>] if &msg[0..=7] == "[\"EOSE\"," { let start = if msg.as_bytes().get(8).copied() == Some(b' ') { - 10 + 10 // Skip space after the comma } else { - 9 + 9 // Start immediately after the comma }; - let end = msg.len() - 2; - return Ok(Self::eose(&msg[start..end])); + + // Use rfind to locate the last quote + if let Some(end_bracket_index) = msg.rfind(']') { + let end = end_bracket_index - 1; // Account for space before bracket + if start < end { + // Trim subscription id and remove extra spaces and quotes + let subid = &msg[start..end].trim().trim_matches('"').trim(); + return Ok(RelayMessage::eose(subid)); + } + } + return Err(Error::DecodeFailed( + "Invalid subscription ID or format".into(), + )); } // OK (NIP-20)