From 4b01295d9fa1299b58c72eaec8aa1fb769d2ef3e Mon Sep 17 00:00:00 2001 From: johannesd3 Date: Sat, 10 Apr 2021 11:43:57 +0200 Subject: [PATCH] Bug fix --- core/src/mercury/mod.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/core/src/mercury/mod.rs b/core/src/mercury/mod.rs index 9dc4f4181..cdcce4bff 100644 --- a/core/src/mercury/mod.rs +++ b/core/src/mercury/mod.rs @@ -198,7 +198,7 @@ impl MercuryManager { let header: protocol::mercury::Header = protobuf::parse_from_bytes(&header_data).unwrap(); let response = MercuryResponse { - uri: form_urlencoded::byte_serialize(header.get_uri().as_bytes()).collect(), + uri: header.get_uri().to_string(), status_code: header.get_status_code(), payload: pending.parts, }; @@ -213,8 +213,22 @@ impl MercuryManager { } else if cmd == 0xb5 { self.lock(|inner| { let mut found = false; + + // TODO: This is just a workaround to make utf-8 encoded usernames work. + // A better solution would be to use an uri struct and urlencode it directly + // before sending while saving the subscription under its unencoded form. + let mut uri_split = response.uri.split('/'); + + let encoded_uri = std::iter::once(uri_split.next().unwrap().to_string()) + .chain( + uri_split + .map(|component| form_urlencoded::byte_serialize(component.as_bytes()).collect::()) + ) + .collect::>() + .join("/"); + inner.subscriptions.retain(|&(ref prefix, ref sub)| { - if response.uri.starts_with(prefix) { + if encoded_uri.starts_with(prefix) { found = true; // if send fails, remove from list of subs