Skip to content

Commit b293257

Browse files
authored
fix-no-newline-parse (#102)
* fix-no-newline-parse Dearest Reviewer, Issue #90 brought up the issue that if there was no newline. the user provided an easy reproduction case. I was able to track it down to the parse raw function. The issue is that the loop hits the end of the string and returns Empty. However, if there is a start offset then some characters were found. This code just checks the offset after the loop. If this is not the correct behavior please close. Thanks for your time Becker * pr feedback Add break instead of duplicating code.
1 parent 41a96cd commit b293257

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/parsers/fields/raw.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ impl<'x> MessageStream<'x> {
1515
match ch {
1616
b'\n' => {
1717
if !self.try_next_is_space() {
18-
return if token_start > 0 {
19-
HeaderValue::Text(String::from_utf8_lossy(
20-
self.bytes(token_start - 1..token_end),
21-
))
22-
} else {
23-
HeaderValue::Empty
24-
};
18+
break;
2519
} else {
2620
continue;
2721
}
@@ -37,7 +31,13 @@ impl<'x> MessageStream<'x> {
3731
token_end = self.offset();
3832
}
3933

40-
HeaderValue::Empty
34+
if token_start > 0 {
35+
HeaderValue::Text(String::from_utf8_lossy(
36+
self.bytes(token_start - 1..token_end),
37+
))
38+
} else {
39+
HeaderValue::Empty
40+
}
4141
}
4242

4343
pub fn parse_and_ignore(&mut self) {
@@ -70,6 +70,7 @@ mod tests {
7070
"for <mary@example.net>; 21 Nov 1997 10:05:43 -0600"
7171
),
7272
),
73+
("Re: Saying Hello", "Re: Saying Hello"), // No newline test
7374
];
7475

7576
for (input, expected) in inputs {

0 commit comments

Comments
 (0)