From 11b9a15dfb34b6298ac209e5805b21383478ce68 Mon Sep 17 00:00:00 2001 From: Лач Date: Tue, 21 Jul 2020 09:34:40 +0000 Subject: [PATCH] fix: faster std.format skips last string element --- --- a/crates/jrsonnet-evaluator/src/builtin/format.rs +++ b/crates/jrsonnet-evaluator/src/builtin/format.rs @@ -252,10 +252,12 @@ while offset != bytes.len() && bytes[offset] != b'%' { offset += 1; } + if offset != 0 { + out.push(Element::String(&str[0..offset])); + } if offset == bytes.len() { return Ok(out); } - out.push(Element::String(&str[0..offset])); str = &str[offset + 1..]; let (code, nstr) = parse_code(str)?; str = nstr; @@ -696,7 +698,14 @@ #[test] fn parse() { - println!("{:?}", parse_codes("Hello %s world!!! %s %(aaa)s ww")); + assert_eq!( + parse_codes( + "How much error budget is left looking at our %.3f%% availability gurantees?" + ) + .unwrap() + .len(), + 4 + ); } #[test] -- gitstuff