From e627423a7107fefba0f762a2d626c081228db15d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 28 Oct 2026 17:49:48 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20drive:=20the=20search?= =?UTF-8?q?=20query=20drops=20control=20and=20bidi=20characters=20before?= =?UTF-8?q?=20it=20is=20echoed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/in-core/src/names.rs | 11 +++++++++++ crates/in-web/src/pages/drive.rs | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) 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?