Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannesd3 committed Apr 10, 2021
1 parent c72cb84 commit 4b01295
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions core/src/mercury/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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::<String>())
)
.collect::<Vec<String>>()
.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
Expand Down

0 comments on commit 4b01295

Please sign in to comment.