diff --git a/src/builtin/string.rs b/src/builtin/string.rs index a7dac57..5b0bf16 100644 --- a/src/builtin/string.rs +++ b/src/builtin/string.rs @@ -57,6 +57,7 @@ pub(crate) fn register(f: &mut BTreeMap) { }; let mut end = match arg!(args, 2, "end-at"=Value::Null).eval() { Value::Dimension(n, Unit::None) if n.to_integer().is_positive() => n.to_integer().to_usize().unwrap(), + Value::Dimension(n, Unit::None) if n == Number::from(0) => 0_usize, Value::Dimension(n, Unit::None) if n < -Number::from(str_len) => 0_usize, Value::Dimension(n, Unit::None) => (BigInt::from(str_len + 1) + n.to_integer()).to_usize().unwrap(), Value::Dimension(..) => todo!("$end: Expected ___ to have no units."), diff --git a/tests/strings.rs b/tests/strings.rs index 8f955d9..6be6930 100644 --- a/tests/strings.rs +++ b/tests/strings.rs @@ -78,3 +78,8 @@ test!( "a {\n color: str-slice(\"cde\", 0, -100);\n}\n", "a {\n color: \"\";\n}\n" ); +test!( + str_slice_end_0, + "a {\n color: str-slice(\"cde\", 1, 0);\n}\n", + "a {\n color: \"\";\n}\n" +);