room-history: Fix parsing of matrix.to URIs

ruma_common::serde::urlencoded::de chokes when there are several identical
keys, so replace it with form_urlencoded.

URIs with encoded HTML entities now recognize & in the query.
This commit is contained in:
Kévin Commaille 2022-10-09 14:56:52 +02:00
parent 7e212947fe
commit 0225b10ab7
No known key found for this signature in database
GPG key ID: DD507DAE96E8245C
3 changed files with 23 additions and 7 deletions

16
Cargo.lock generated
View file

@ -1062,6 +1062,7 @@ dependencies = [
"gstreamer-video",
"gtk-macros",
"gtk4",
"html-escape",
"html2pango",
"image 0.23.14",
"indexmap",
@ -1970,6 +1971,15 @@ dependencies = [
"digest 0.10.3",
]
[[package]]
name = "html-escape"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8e7479fa1ef38eb49fb6a42c426be515df2d063f06cb8efd3e50af073dbc26c"
dependencies = [
"utf8-width",
]
[[package]]
name = "html2pango"
version = "0.5.0"
@ -4685,6 +4695,12 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
[[package]]
name = "utf8-width"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5190c9442dcdaf0ddd50f37420417d219ae5261bbf5db120d0f9bab996c9cba1"
[[package]]
name = "uuid"
version = "0.8.2"

View file

@ -54,6 +54,7 @@ rqrr = "0.4.0"
secular = { version = "1.0.1", features = ["bmp", "normalization"] }
pulldown-cmark = "0.9.2"
geo-uri = "0.2.0"
html-escape = "0.2.11"
[dependencies.sourceview]
package = "sourceview5"

View file

@ -5,7 +5,7 @@ pub mod media;
pub mod sourceview;
pub mod template_callbacks;
use std::{collections::HashMap, path::PathBuf};
use std::path::PathBuf;
use futures::{
future::{self, Either, Future},
@ -19,10 +19,10 @@ use matrix_sdk::ruma::{EventId, OwnedEventId, OwnedTransactionId, TransactionId,
use once_cell::sync::Lazy;
use regex::Regex;
use ruma::{
exports::percent_encoding::percent_decode_str, matrix_uri::MatrixId, serde::urlencoded,
IdParseError, MatrixIdError, MatrixToError, OwnedServerName, RoomAliasId, RoomId, ServerName,
UserId,
exports::percent_encoding::percent_decode_str, matrix_uri::MatrixId, IdParseError,
MatrixIdError, MatrixToError, OwnedServerName, RoomAliasId, RoomId, ServerName, UserId,
};
use url::form_urlencoded;
/// Returns an expression that is the anded result of the given boolean
/// expressions.
@ -285,10 +285,9 @@ pub fn parse_matrix_to_uri(uri: &str) -> Result<(MatrixId, Vec<OwnedServerName>)
let via = parts
.next()
.map(|query| {
let query_parts = urlencoded::from_str::<HashMap<String, String>>(query)
.or(Err(MatrixToError::InvalidUrl))?;
let query = html_escape::decode_html_entities(query);
let query_parts = form_urlencoded::parse(query.as_bytes());
query_parts
.into_iter()
.filter_map(|(key, value)| (key == "via").then(|| ServerName::parse(&value)))
.collect::<Result<Vec<_>, _>>()
})