Skip to content

Commit 0919915

Browse files
committed
Don't prepend anything when gb18030 range decode fails per whatwg/encoding#110.
1 parent 6779eaa commit 0919915

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ encoding_rs is
9696

9797
## Release Notes
9898

99+
### 0.6.9
100+
101+
* [Don't prepend anything when gb18030 range decode
102+
fails](https://github.com/whatwg/encoding/issues/110). (Spec change.)
103+
99104
### 0.6.8
100105

101106
* Correcly handle the case where the first buffer contains potentially

src/gb18030.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,8 @@ impl Gb18030Decoder {
267267
// Astral
268268
handle.write_astral((pointer - (189000usize - 0x10000usize)) as u32)
269269
} else {
270-
self.pending_ascii = Some(second_minus_offset + 0x30);
271-
self.pending = Gb18030Pending::One(third_minus_offset);
272-
return (DecoderResult::Malformed(1, 2),
273-
unread_handle_fourth.unread(),
270+
return (DecoderResult::Malformed(4, 0),
271+
unread_handle_fourth.consumed(),
274272
handle.written());
275273
}
276274
},
@@ -598,11 +596,8 @@ mod tests {
598596
decode_gb18030(b"\x81\x37\xA3\x30", "\u{2603}");
599597
decode_gb18030(b"\x94\x39\xDA\x33", "\u{1F4A9}");
600598
decode_gb18030(b"\xE3\x32\x9A\x35", "\u{10FFFF}");
601-
decode_gb18030(b"\xE3\x32\x9A\x36\x81\x30", "\u{FFFD}\u{0032}\u{309B8}");
602-
decode_gb18030(
603-
b"\xE3\x32\x9A\x36\x81\x40",
604-
"\u{FFFD}\u{0032}\u{FFFD}\u{0036}\u{4E02}",
605-
);
599+
decode_gb18030(b"\xE3\x32\x9A\x36\x81\x30", "\u{FFFD}\u{FFFD}");
600+
decode_gb18030(b"\xE3\x32\x9A\x36\x81\x40", "\u{FFFD}\u{4E02}");
606601
decode_gb18030(b"\xE3\x32\x9A", "\u{FFFD}"); // not \u{FFFD}\u{0032}\u{FFFD} !
607602

608603
}

src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,10 +2920,9 @@ pub enum DecoderResult {
29202920
/// the malformed sequence. Note that the malformed bytes may have been part
29212921
/// of an earlier input buffer.
29222922
///
2923-
/// The first wrapped integer can have values 1, 2 or 3. The second
2924-
/// wrapped integer can have values 0, 1, 2 or 3. This makes the
2925-
/// worst-case sum of the two 6, and the worst case actually happens with
2926-
/// ISO-2022-JP.
2923+
/// The first wrapped integer can have values 1, 2, 3 or 4. The second
2924+
/// wrapped integer can have values 0, 1, 2 or 3. The worst-case sum
2925+
/// of the two is 6, which happens with ISO-2022-JP.
29272926
Malformed(u8, u8), // u8 instead of usize to avoid useless bloat
29282927
}
29292928

0 commit comments

Comments
 (0)