diff --git a/crates/dxf/src/lib.rs b/crates/dxf/src/lib.rs index c140ee513..0109e9040 100644 --- a/crates/dxf/src/lib.rs +++ b/crates/dxf/src/lib.rs @@ -768,7 +768,7 @@ fn ascii(tags: &[Tag], strings: Strings) -> Vec { /// Write tags as binary DXF (DXF Reference, "Binary DXF Files", R13+ layout): the sentinel, /// then per tag a 2-byte little-endian group code and the value in the binary form of the code's /// [`Kind`]: a zero-terminated string, an 8-byte real, a 2-, 4- or 8-byte integer, a 1-byte -/// boolean, or a binary chunk (one length byte, then up to 255 bytes; longer data is split into +/// boolean, or a binary chunk (one length byte, then up to 127 bytes; longer data is split into /// several groups of the same code). Strings are UTF-8 when `utf8` (R2007+), otherwise escaped as /// in [`write_ascii`]. A tag's value is converted to its code's kind, so a number written as text /// is stored as a number; a code outside the 16-bit range is skipped. @@ -822,8 +822,8 @@ fn binary(tags: &[Tag], strings: Strings) -> Vec { } Kind::Hex => { let bytes = hex_bytes(&t.value.as_str()); - // An empty chunk is still one group, as in ASCII. - let mut chunks: Vec<&[u8]> = bytes.chunks(255).collect(); + // At most 127 bytes per group, as in ASCII; an empty chunk is still one group. + let mut chunks: Vec<&[u8]> = bytes.chunks(127).collect(); if chunks.is_empty() { chunks.push(&[]); } diff --git a/crates/dxf/tests/binary_write.rs b/crates/dxf/tests/binary_write.rs index fb2d08210..4ecaf1709 100644 --- a/crates/dxf/tests/binary_write.rs +++ b/crates/dxf/tests/binary_write.rs @@ -44,9 +44,8 @@ fn binary_converts_values_to_their_codes_kind() { let back = parse(&write_binary(&tags, true)).unwrap(); assert_eq!(back[0], Tag::i(70, 12)); assert_eq!(back[1], Tag::i(62, i64::from(i16::MAX))); - assert_eq!(back[2].code, 310); - assert_eq!(back[3].code, 310, "300 bytes are split into chunks of at most 255"); - assert_eq!(back[2].str().len() + back[3].str().len(), 600); + let sizes: Vec = back.iter().filter(|t| t.code == 310).map(|t| t.str().len()).collect(); + assert_eq!(sizes, vec![254, 254, 92], "300 bytes are split into chunks of at most 127 (254 hex digits)"); } #[test] diff --git a/crates/dxf/tests/hex_chunks.rs b/crates/dxf/tests/hex_chunks.rs index 61100b082..80e9e9193 100644 --- a/crates/dxf/tests/hex_chunks.rs +++ b/crates/dxf/tests/hex_chunks.rs @@ -2,7 +2,6 @@ //! 1004 specify at most 127 payload bytes per chunk, even though a length byte represents 255. //! Inspect writer bytes without our parser; accept any compliant partition preserving payload, //! code and following-record framing. Oversized binary read fixtures test tolerance only. -//! Pending writer regressions extend the chunk-size finding in issue #1025. //! Public DXF Reference, Group Codes in Numerical Order and Binary DXF Files: //! //! @@ -100,7 +99,6 @@ fn binary_reader_tolerates_the_full_length_byte_domain() { } #[test] -#[ignore = "Confirmed ASCII DXF writer nonconformance: hex payloads above 127 bytes are emitted as one oversized chunk"] fn ascii_writer_splits_large_payloads_into_conforming_chunks() { for code in (310..=319).chain([1004]) { for length in [128, 254, 255, 256, 1024] { @@ -112,7 +110,6 @@ fn ascii_writer_splits_large_payloads_into_conforming_chunks() { } #[test] -#[ignore = "Confirmed binary DXF writer nonconformance: 255-byte partitioning exceeds the documented 127-byte group limit"] fn binary_writer_splits_large_payloads_into_conforming_chunks() { for code in (310..=319).chain([1004]) { for length in [128, 254, 255, 256, 1024] { diff --git a/crates/dxf/tests/roundtrip.rs b/crates/dxf/tests/roundtrip.rs index 87f1e812c..362bc725f 100644 --- a/crates/dxf/tests/roundtrip.rs +++ b/crates/dxf/tests/roundtrip.rs @@ -120,7 +120,7 @@ fn hex_chunks_keep_bytes_and_order() { // DXF groups 310–319 and 1004 permit 127 payload bytes per chunk. A binary length // byte can represent more, but that is reader tolerance, not writer conformance. // Larger payloads need chunk-size/reassembly checks rather than exact tag equality; - // see hex_chunks.rs for the independent wire checks and pending writer regressions. + // see hex_chunks.rs for the independent wire checks. for length in [0, 1, 2, 126, 127] { let hex: String = (0..length).fold(String::new(), |mut out, i| { use std::fmt::Write as _;