Rewrite your app in Rust, piece by piece, checked against the original at every step. Works with TypeScript, JavaScript, Python, Go, Ruby, Java, C, PHP, C#, Kotlin, PowerShell and Swift.
Rust agent-skillsclaude-codeclicode-migrationcodexffigolangjavajavascriptmcpmigrationnapiperformanceportingpyo3pythonrewriterubyrusttypescript
fix(mime): preserve literal percent escapes in split filenames (#1439)
Atharva Dahaked16631ce2110
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 644f91a2..ec50f257 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,8 @@## Unreleased+- Recorded SMTP attachments preserve literal percent escapes in plain pieces of a split filename+ (#1314).- C# wrapper headers, generated `README.md`, and `shadow` refusals now name the unit's actual `<namespace>.Rust` namespace(s) and first real class alias instead of `<namespace>.Rust` and `Acme.Text.Rust.Slug` (#1381 by @m3lonxd).- `gate`'s `accepted diffs` check now prints a single `--accept-known-diffs <N>` command when both rules fail (naming the count that clears both), and updates `fix:`, `gate --help`, and MCP tool documentation to clarify entries vs. accepted cases (#1349 by @m3lonxd).- `profile` and `go` on a C repository say they do not run C workloads yet and name Instruments' Time Profiler on macOS alongside `perf record -g` on Linux, matching other unsupported languages (#1398 by @m3lonxd).diff --git a/src/mime.rs b/src/mime.rsindex 60ed1cd2..18a8be9c 100644--- a/src/mime.rs+++ b/src/mime.rs@@ -258,16 +258,28 @@ fn parse_header_params(raw: &str) -> (String, BTreeMap<String, String>) {let mut params = plain;for (name, pieces) in cont {- let mut combined = String::new();- let mut any_ext = false;- for (_, (is_ext, piece)) in pieces {- any_ext |= is_ext;- combined.push_str(&piece);+ let mut combined = Vec::new();+ let mut charset = None;+ for (&idx, (is_ext, piece)) in &pieces {+ if *is_ext {+ let mut encoded = piece.as_str();+ if idx == 0+ && let Some((label, rest)) = piece.split_once('\'')+ && let Some((_, value)) = rest.split_once('\'')+ {+ charset = Some(label);+ encoded = value;+ }+ charset.get_or_insert("utf-8");+ combined.extend(percent_decode_str(encoded));+ } else {+ combined.extend_from_slice(piece.as_bytes());+ }}- let decoded = if any_ext {- decode_rfc2231(&combined)+ let decoded = if let Some(charset) = charset {+ decode_charset(&combined, charset)} else {- decode_header_value(&combined)+ decode_header_value(&String::from_utf8_lossy(&combined))};params.insert(name, decoded);}@@ -822,6 +834,38 @@ JVBERi0xLjQ=\r\n\);}+ #[test]+ fn rfc2231_filename_continuations() {+ for (header, expected) in [+ (+ "attachment; filename*0*=UTF-8''caf%C3%A9; filename*1*=%20menu.pdf",+ "café menu.pdf",+ ),+ (+ "attachment; filename*1*=%20menu.pdf; filename*0*=UTF-8''caf%C3%A9",+ "café menu.pdf",+ ),+ (+ r#"attachment; filename*0*=UTF-8''a%20b; filename*1="_50%41.txt""#,+ "a b_50%41.txt",+ ),+ (r#"attachment; filename*10="b"; filename*2="a""#, "ab"),+ (+ "attachment; filename*0*=UTF-8''caf%C3; filename*1*=%A9.pdf",+ "café.pdf",+ ),+ (+ "attachment; filename*0*=ISO-8859-1'fr'caf; filename*1*=%E9.pdf",+ "café.pdf",+ ),+ (r#"attachment; filename="a;b.txt""#, "a;b.txt"),+ ] {+ let (_, params) = parse_header_params(header);+ assert_eq!(params["filename"], expected, "{header}");+ }+ assert_eq!(unquote_param(r#""a \"b\" c""#), r#"a "b" c"#);+ }+#[test]fn iso_2022_jp_encoded_words_keep_their_boundaries() {// Each word encodes あ and returns to ASCII; joining their bytes would put two