summaryrefslogtreecommitdiffstats
path: root/src/normalize.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/normalize.rs')
-rw-r--r--src/normalize.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/normalize.rs b/src/normalize.rs
index 7c8487d..3774f73 100644
--- a/src/normalize.rs
+++ b/src/normalize.rs
@@ -350,7 +350,18 @@ fn decode_text_data_to_buf(
_ => Err("unknown encoding".into()),
};
- if result.is_err() {
+ if result.is_ok() {
+ // During decoding the final CRLF/LF in the data may be dropped.
+ // Restore it to ensure that subsequent lines don't get folded
+ // with the decoded data.
+ const CRLF: &[u8] = &[b'\r', b'\n'];
+ const LF: &[u8] = &[b'\n'];
+ if data.ends_with(CRLF) && !out.ends_with(CRLF) {
+ out.extend(CRLF);
+ } else if data.ends_with(LF) && !out.ends_with(LF) {
+ out.extend(LF);
+ }
+ } else {
out.resize(initial_len, 0);
should_convert_charset = false;
}