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.
This commit is contained in:
Mark Schmale 2018-09-13 10:49:05 +02:00
parent b2fdd96ccc
commit fc804cb874

View File

@ -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<Format, FormatParserError> {
(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)?))
}