forge
Explore
Log in

Don't you dare go Hollow

🛡️ drive: the search query drops control and bidi characters before it is echoed

Browse files at this commit

e627423a7107fefba0f762a2d626c081228db15dAhmet Kaan GümüşParent: c816f91
crates/in-core/src/names.rsmodified+11 -0
@@ -97,6 +97,17 @@ pub fn display_name(input: &str) -> String {
97 truncate_chars(trimmed, MAX_NAME_CHARS)97 truncate_chars(trimmed, MAX_NAME_CHARS)
98 }98 }
99 99
100+/// A search query as typed: control characters, bidi controls and invisible formatting characters removed,
101+/// then trimmed, so the query echoed back into the search box carries none of them.
102+pub fn search_text(input: &str) -> String {
103+ input
104+ .chars()
105+ .filter(|c| !c.is_control() && !is_invisible_or_bidi(*c))
106+ .collect::<String>()
107+ .trim()
108+ .to_owned()
109+}
110+
100 /// The name to try after a clash: `report.txt` with `n = 2` gives `report (2).txt`. A folder gets the111 /// The name to try after a clash: `report.txt` with `n = 2` gives `report (2).txt`. A folder gets the
101 /// suffix at the end (`root (2)`), and so does a file with no extension (`note (2)`). A name starting112 /// suffix at the end (`root (2)`), and so does a file with no extension (`note (2)`). A name starting
102 /// with a dot has no extension, so `.bashrc` gives `.bashrc (2)`. The stem is cut so the whole result113 /// with a dot has no extension, so `.bashrc` gives `.bashrc (2)`. The stem is cut so the whole result
crates/in-web/src/pages/drive.rsmodified+2 -2
@@ -401,7 +401,7 @@ pub async fn search_board(
401 query: &ListQuery,401 query: &ListQuery,
402 lang: Lang,402 lang: Lang,
403 ) -> Result<Board> {403 ) -> Result<Board> {
404- let q = query.q.trim().to_owned();404+ let q = in_core::names::search_text(&query.q);
405 let mut listing = state405 let mut listing = state
406 .store406 .store
407 .search(&viewer.member.sub, &q, SEARCH_LIMIT)407 .search(&viewer.member.sub, &q, SEARCH_LIMIT)
@@ -539,7 +539,7 @@ async fn drive_root_page(cx: &Cx) -> Result<impl View> {
539 let viewer = require_member(cx).await?;539 let viewer = require_member(cx).await?;
540 let lang = viewer_lang(cx, &viewer);540 let lang = viewer_lang(cx, &viewer);
541 let query: ListQuery = parse_query_params(cx).unwrap_or_default();541 let query: ListQuery = parse_query_params(cx).unwrap_or_default();
542- let board = if query.q.trim().is_empty() {542+ let board = if in_core::names::search_text(&query.q).is_empty() {
543 folder_board(state, &viewer, None, &query, lang).await?543 folder_board(state, &viewer, None, &query, lang).await?
544 } else {544 } else {
545 search_board(state, &viewer, &query, lang).await?545 search_board(state, &viewer, &query, lang).await?