diff --git a/crates/in-core/src/names.rs b/crates/in-core/src/names.rs index 6b31bd8..3ca1c89 100644 --- a/crates/in-core/src/names.rs +++ b/crates/in-core/src/names.rs @@ -97,6 +97,17 @@ pub fn display_name(input: &str) -> String { truncate_chars(trimmed, MAX_NAME_CHARS) } +/// A search query as typed: control characters, bidi controls and invisible formatting characters removed, +/// then trimmed, so the query echoed back into the search box carries none of them. +pub fn search_text(input: &str) -> String { + input + .chars() + .filter(|c| !c.is_control() && !is_invisible_or_bidi(*c)) + .collect::() + .trim() + .to_owned() +} + /// The name to try after a clash: `report.txt` with `n = 2` gives `report (2).txt`. A folder gets the /// suffix at the end (`root (2)`), and so does a file with no extension (`note (2)`). A name starting /// with a dot has no extension, so `.bashrc` gives `.bashrc (2)`. The stem is cut so the whole result diff --git a/crates/in-web/src/pages/drive.rs b/crates/in-web/src/pages/drive.rs index 79cb8ac..630b5bf 100644 --- a/crates/in-web/src/pages/drive.rs +++ b/crates/in-web/src/pages/drive.rs @@ -401,7 +401,7 @@ pub async fn search_board( query: &ListQuery, lang: Lang, ) -> Result { - let q = query.q.trim().to_owned(); + let q = in_core::names::search_text(&query.q); let mut listing = state .store .search(&viewer.member.sub, &q, SEARCH_LIMIT) @@ -539,7 +539,7 @@ async fn drive_root_page(cx: &Cx) -> Result { let viewer = require_member(cx).await?; let lang = viewer_lang(cx, &viewer); let query: ListQuery = parse_query_params(cx).unwrap_or_default(); - let board = if query.q.trim().is_empty() { + let board = if in_core::names::search_text(&query.q).is_empty() { folder_board(state, &viewer, None, &query, lang).await? } else { search_board(state, &viewer, &query, lang).await?