Merge branch 'emptysearchcrash' into 'next'

fix: crash on empty search

Closes #190

See merge request famedly/conduit!286
This commit is contained in:
Timo Kösters 2022-02-04 16:42:56 +00:00
commit dffa5570e7
4 changed files with 22 additions and 20 deletions

2
Cargo.lock generated
View File

@ -2018,7 +2018,7 @@ dependencies = [
[[package]]
name = "reqwest"
version = "0.11.9"
source = "git+https://github.com/niuhuan/reqwest?branch=dns-resolver-fn#57b7cf4feb921573dfafad7d34b9ac6e44ead0bd"
source = "git+https://github.com/timokoesters/reqwest?rev=57b7cf4feb921573dfafad7d34b9ac6e44ead0bd#57b7cf4feb921573dfafad7d34b9ac6e44ead0bd"
dependencies = [
"base64 0.13.0",
"bytes",

View File

@ -48,7 +48,7 @@ rand = "0.8.4"
# Used to hash passwords
rust-argon2 = "0.8.3"
# Used to send requests
reqwest = { version = "0.11.4", default-features = false, features = ["rustls-tls", "socks"], git = "https://github.com/niuhuan/reqwest", branch = "dns-resolver-fn" }
reqwest = { default-features = false, features = ["rustls-tls", "socks"], git = "https://github.com/timokoesters/reqwest", rev = "57b7cf4feb921573dfafad7d34b9ac6e44ead0bd" }
# Used for conduit::Error type
thiserror = "1.0.28"
# Used to generate thumbnails for images

View File

@ -44,12 +44,13 @@ pub async fn search_events_route(
));
}
let search = db
if let Some(search) = db
.rooms
.search_pdus(&room_id, &search_criteria.search_term)?;
.search_pdus(&room_id, &search_criteria.search_term)?
{
searches.push(search.0.peekable());
}
}
let skip = match body.next_batch.as_ref().map(|s| s.parse()) {
Some(Ok(s)) => s,

View File

@ -2771,7 +2771,7 @@ impl Rooms {
&'a self,
room_id: &RoomId,
search_string: &str,
) -> Result<(impl Iterator<Item = Vec<u8>> + 'a, Vec<String>)> {
) -> Result<Option<(impl Iterator<Item = Vec<u8>> + 'a, Vec<String>)>> {
let prefix = self
.get_shortroomid(room_id)?
.expect("room exists")
@ -2799,19 +2799,20 @@ impl Rooms {
.map(|(key, _)| key[key.len() - size_of::<u64>()..].to_vec())
});
Ok((
utils::common_elements(iterators, |a, b| {
Ok(utils::common_elements(iterators, |a, b| {
// We compare b with a because we reversed the iterator earlier
b.cmp(a)
})
.unwrap()
.map(move |id| {
.map(|iter| {
(
iter.map(move |id| {
let mut pduid = prefix_clone.clone();
pduid.extend_from_slice(&id);
pduid
}),
words,
))
)
}))
}
#[tracing::instrument(skip(self))]