summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Korber <p.korber@1aim.com>2019-03-26 16:01:12 +0100
committerPhilipp Korber <p.korber@dac.eu>2019-10-11 16:33:19 +0200
commit5c7e45e94d1f56d44e5170aa63d9e184234e2449 (patch)
treeef415f1b4be352684ad82384bf37d026f6f1dbb0
parentb3026512aa9ce16c9a159d6d7de22ba0c0b93eb7 (diff)
fix(internals): max line length error breached triggered wrongly
- if the soft line length limit was breached and braking the line failed and the buffer had already reached a certain size a hard line length limit breached error was triggered (but should not have)
-rw-r--r--internals/src/encoder/mod.rs40
1 files changed, 33 insertions, 7 deletions
diff --git a/internals/src/encoder/mod.rs b/internals/src/encoder/mod.rs
index 8903899..760da2f 100644
--- a/internals/src/encoder/mod.rs
+++ b/internals/src/encoder/mod.rs
@@ -721,13 +721,13 @@ impl<'inner> EncodingWriter<'inner> {
}
if self.current_line_byte_length() >= LINE_LEN_SOFT_LIMIT {
- if !self.break_line_on_fws() {
- if self.buffer.len() == LINE_LEN_HARD_LIMIT {
- ec_bail!(
- mail_type: self.mail_type(),
- kind: HardLineLengthLimitBreached
- );
- }
+ self.break_line_on_fws();
+
+ if self.current_line_byte_length() >= LINE_LEN_HARD_LIMIT {
+ ec_bail!(
+ mail_type: self.mail_type(),
+ kind: HardLineLengthLimitBreached
+ );
}
}
@@ -1097,6 +1097,32 @@ mod test {
assert_eq!(encoder.as_slice(), b"H: a\r\n");
}
+ #[test]
+ fn soft_line_limit_can_be_breached() {
+ let mut encoder = EncodingBuffer::new(MailType::Ascii);
+ {
+ let mut handle = encoder.writer();
+ for _ in 0u32..500 {
+ assert_ok!(handle.internal_write_char("a"));
+ }
+ handle.finish_header();
+ }
+ }
+
+ #[test]
+ fn hard_line_limit_can_not_be_breached() {
+ let mut encoder = EncodingBuffer::new(MailType::Ascii);
+ {
+ let mut handle = encoder.writer();
+ for _ in 0u32..998 {
+ assert_ok!(handle.internal_write_char("a"));
+ }
+
+ assert_err!(handle.internal_write_char("b"));
+ handle.finish_header();
+ }
+ }
+
#[test]
fn break_line_on_fws() {
let mut encoder = EncodingBuffer::new(MailType::Ascii);