From db68517cf99b40a4db8373704c6adc5b8ab69adb Mon Sep 17 00:00:00 2001 From: "Muse (new-issue-creator)" Date: Sat, 24 Oct 2026 17:51:22 -0500 Subject: [PATCH] fix(id-web): truncate file-list tag values on a char boundary (#815) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit render_file_list sliced &v[..256] to truncate long tag-pill values, which panics when byte 256 splits a multi-byte UTF-8 character in a user-controlled tag value. Use the crate's existing truncate_on_char_boundary helper (commands::tag) instead, and add a regression test with an é straddling byte 256. --- pkgs/id/src/web/templates.rs | 45 ++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/pkgs/id/src/web/templates.rs b/pkgs/id/src/web/templates.rs index 5a864a0e96..c15673a0ea 100644 --- a/pkgs/id/src/web/templates.rs +++ b/pkgs/id/src/web/templates.rs @@ -259,11 +259,13 @@ pub fn render_file_list_content(page: &FileListPage) -> String { let key_esc = html_escape(key); match value { Some(v) => { - let truncated = if v.len() > crate::tags::TAG_DISPLAY_MAX_BYTES { - format!("{}…", &v[..crate::tags::TAG_DISPLAY_MAX_BYTES]) - } else { - v.clone() - }; + // Truncate on a char boundary: a raw &v[..256] slice + // panics when byte 256 splits a multi-byte character + // (#815). The CLI's helper already handles this. + let truncated = crate::commands::tag::truncate_on_char_boundary( + v, + crate::tags::TAG_DISPLAY_MAX_BYTES, + ); let val_esc = html_escape(&truncated); let _ = write!( tag_pills, @@ -1104,6 +1106,39 @@ mod tests { assert!(html.contains("aria-label=\"Select file test.txt\"")); } + #[test] + fn test_render_file_list_tag_value_straddling_truncation_boundary() { + // Regression (#815): a tag value longer than TAG_DISPLAY_MAX_BYTES + // whose byte-256 offset splits a multi-byte character used to panic + // on &v[..256]. 'é' here occupies bytes 255..257. + let value = format!("{}é{}", "a".repeat(255), "tail-tail-tail"); + assert!(value.len() > crate::tags::TAG_DISPLAY_MAX_BYTES); + let files = vec![FileInfo { + name: "tagged.txt".to_owned(), + display_name: None, + hash: "abc123def456".to_owned(), + size: 1024, + kind: FileKind::Primary, + parent_name: None, + timestamp: None, + created_at: None, + modified_at: None, + tags: vec![("note".to_owned(), Some(value))], + is_deleted: false, + }]; + let page = FileListPage { + total: files.len(), + files, + page: 1, + per_page: 50, + search: None, + show_deleted: false, + }; + let html = render_file_list(&page); + // Truncated on the char boundary before 'é', with the ellipsis. + assert!(html.contains(&format!("note: {}…", "a".repeat(255)))); + } + #[test] fn test_render_peers_empty() { let html = render_peers(&[]);