properly insert into empty strings

This commit is contained in:
ConnorSkees 2020-03-22 18:13:55 -04:00
parent 92809b1d03
commit c392c33ad8
2 changed files with 9 additions and 0 deletions

View File

@ -176,6 +176,10 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
QuoteKind::None => QuoteKind::None,
};
if s1.is_empty() {
return Ok(Value::Ident(substr, quotes));
}
let len = s1.len();
// Insert substring at char position, rather than byte position

View File

@ -141,6 +141,11 @@ test!(
);
test!(
str_insert_empty_string,
"a {\n color: str-insert(\"\", \"abcd\", 4);\n}\n",
"a {\n color: \"abcd\";\n}\n"
);
test!(
str_insert_empty_substring,
"a {\n color: str-insert(abcd, \"\", 4);\n}\n",
"a {\n color: abcd;\n}\n"
);