From 909d074ed2ffa36b807dcf852d77ebfcb8b82bd5 Mon Sep 17 00:00:00 2001 From: ldm0 Date: Sun, 11 Oct 2026 18:18:57 +0800 Subject: [PATCH] fix(encoding): deduplicate XHR decoder tests after main rebase Main and the historical XHR integration both added the same two decoder tests. Keep one byte-identical copy of each function, preserving both test names and every case. Resolve the overlapping decoder file using main's DocumentStreamingDecoder and byte header API. Validate the complete rebased source with repository fmt, workspace all-target/all-feature clippy and full nextest at 32 workers with zero retries. --- moli-encoding/src/tests.rs | 132 ------------------------------------- 1 file changed, 132 deletions(-) diff --git a/moli-encoding/src/tests.rs b/moli-encoding/src/tests.rs index f672fb6565c..ef9d2fd5565 100644 --- a/moli-encoding/src/tests.rs +++ b/moli-encoding/src/tests.rs @@ -1688,135 +1688,3 @@ fn header_charset_keeps_an_escaped_quote_as_data() { assert_eq!(label, "utf-8\""); assert!(encoding_for_label(&label).is_none()); } - -#[test] -fn xhr_response_decoder_preserves_encoding_across_every_chunk_boundary() { - use XhrResponseTextKind::{Html, Text, Xml}; - let xml = b"\xff"; - let xml_utf16 = "é"; - let cases = [ - ( - Text, - None, - b"\xef\xbb\xbf\xe6\xa9\x9f".to_vec(), - "機", - "UTF-8", - ), - ( - Text, - Some(encoding_rs::WINDOWS_1252), - b"\xef\xbb\xbf\xe6\xa9\x9f".to_vec(), - "機", - "UTF-8", - ), - ( - Text, - None, - b"\xef\xbb\xbf\xef\xbb\xbf".to_vec(), - "\u{feff}", - "UTF-8", - ), - (Text, None, b"\xff\xfeA\0\xe9\0".to_vec(), "Aé", "UTF-16LE"), - ( - Text, - Some(encoding_rs::UTF_8), - b"\xfe\xff\0A\0\xe9".to_vec(), - "Aé", - "UTF-16BE", - ), - ( - Text, - Some(encoding_rs::UTF_16LE), - b"\xe9\0".to_vec(), - "é", - "UTF-16LE", - ), - ( - Text, - Some(encoding_rs::SHIFT_JIS), - b"\x83e\x83X\x83g".to_vec(), - "テスト", - "Shift_JIS", - ), - (Text, None, b"a\xc2".to_vec(), "a\u{fffd}", "UTF-8"), - ( - Xml, - None, - xml.to_vec(), - "ÿ", - "windows-1252", - ), - ( - Xml, - Some(encoding_rs::UTF_8), - xml.to_vec(), - "\u{fffd}", - "UTF-8", - ), - ( - Text, - None, - xml.to_vec(), - "\u{fffd}", - "UTF-8", - ), - ( - Xml, - None, - xml_utf16 - .encode_utf16() - .flat_map(u16::to_le_bytes) - .collect(), - xml_utf16, - "UTF-16LE", - ), - ( - Html, - None, - b"\xff".to_vec(), - "ÿ", - "windows-1252", - ), - ( - Html, - Some(encoding_rs::UTF_8), - b"\xff".to_vec(), - "\u{fffd}", - "UTF-8", - ), - ( - Html, - None, - b"\xe6\xa9\x9f".to_vec(), - "機", - "UTF-8", - ), - ]; - for (kind, transport, bytes, expected, encoding) in cases { - for boundary in 0..=bytes.len() { - let mut decoder = XhrResponseDecoder::new(kind, transport); - let mut text = decoder.push(&bytes[..boundary]); - text.push_str(&decoder.push(&bytes[boundary..])); - text.push_str(&decoder.finish()); - assert_eq!(text, expected, "boundary={boundary}, bytes={bytes:?}"); - assert_eq!(decoder.encoding_name(), encoding); - } - } -} - -#[test] -fn xhr_response_decoder_defers_partial_boms_and_flushes_incomplete_sequences() { - let mut decoder = XhrResponseDecoder::new(XhrResponseTextKind::Text, None); - assert_eq!(decoder.push(b"\xef"), ""); - assert_eq!(decoder.push(b"\xbb"), ""); - assert_eq!(decoder.push(b"\xbf"), ""); - assert_eq!(decoder.push(b"a\xc2"), "a"); - assert_eq!(decoder.finish(), "\u{fffd}"); - - let mut decoder = XhrResponseDecoder::new(XhrResponseTextKind::Text, None); - assert_eq!(decoder.push(b"\xff"), ""); - assert_eq!(decoder.push(b"\xfeA"), ""); - assert_eq!(decoder.push(b"\0\xe9"), "A"); - assert_eq!(decoder.push(b"\0"), "é"); - assert_eq!(decoder.finish(), ""); -}