From fc804cb874c99883aaf6988f2175b6f63e855fd0 Mon Sep 17 00:00:00 2001 From: Mark Schmale Date: Thu, 13 Sep 2018 10:49:05 +0200 Subject: [PATCH] fix(format_parser): support two variables with no fixed part in between. this will cause problems for the line parser, but its still possible to happen in the real world. --- src/format.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/format.rs b/src/format.rs index 9aeb615..f921102 100644 --- a/src/format.rs +++ b/src/format.rs @@ -155,6 +155,7 @@ fn read_byte(chr: u8, index: usize, state: &FormatParserState) -> FormatParserSt }, Variable(start, _end) => match chr { x if is_var_char(x) => Variable(*start, index + 1), + b'$' => Variable(index, index + 1), _ => Fixed(index, index + 1), }, Fixed(start, _end) => match chr { @@ -180,6 +181,9 @@ fn read_format(bytes: &[u8]) -> Result { (Variable(start, end), Fixed(_, _)) => stack.push(FormatPart::Variable( create_owned_str(&bytes, *start, *end)?, )), + (Variable(start, end), Variable(b_start, _)) if b_start > start => stack.push(FormatPart::Variable( + create_owned_str(&bytes, *start, *end)?, + )), (Fixed(start, end), Variable(_, _)) => { stack.push(FormatPart::Fixed(create_owned_str(&bytes, *start, *end)?)) }