From b64c032bff25a875d431ece24db5cd12f93b3c36 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 25 Jul 2023 18:27:19 +0200 Subject: [PATCH] add compatibility for \r\r\n --- src/text/ascii.rs | 5 +++++ src/text/whitespace.rs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/text/ascii.rs b/src/text/ascii.rs index 9f37738..9c81bb1 100644 --- a/src/text/ascii.rs +++ b/src/text/ascii.rs @@ -136,6 +136,11 @@ pub const TILDE: u8 = 0x7E; // ~ // GROUP OF CHARACTERS // -- CRLF pub const CRLF: &[u8] = &[CR, LF]; +// -- CRCRLF +// Sometimes portable libraries replace transparently +// the "\n" with "\r\n" on Windows. When developpers +// explicitly write "\r\n", the library generates "\r\r\n". +pub const CRCRLF: &[u8] = &[CR, CR, LF]; // -- WHITESPACE pub const WS: &[u8] = &[HT, SP]; diff --git a/src/text/whitespace.rs b/src/text/whitespace.rs index 0e8650a..c48e347 100644 --- a/src/text/whitespace.rs +++ b/src/text/whitespace.rs @@ -22,7 +22,7 @@ use nom::{ /// \r or \n is allowed nowhere else, so we also add this support. pub fn obs_crlf(input: &[u8]) -> IResult<&[u8], &[u8]> { - alt((tag(ascii::CRLF), tag(&[ascii::CR]), tag(&[ascii::LF])))(input) + alt((tag(ascii::CRLF), tag(ascii::CRCRLF), tag(&[ascii::CR]), tag(&[ascii::LF])))(input) } /// ```abnf