str-len is a count of characters, not bytes
This commit is contained in:
parent
c392c33ad8
commit
d19c112765
@ -35,7 +35,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
||||
Box::new(|args, _| {
|
||||
max_args!(args, 1);
|
||||
match arg!(args, 0, "string") {
|
||||
Value::Ident(i, _) => Ok(Value::Dimension(Number::from(i.len()), Unit::None)),
|
||||
Value::Ident(i, _) => Ok(Value::Dimension(Number::from(i.chars().count()), Unit::None)),
|
||||
v => Err(format!("$string: {} is not a string.", v).into()),
|
||||
}
|
||||
}),
|
||||
|
@ -103,6 +103,16 @@ test!(
|
||||
"a {\n color: str-length(\"foo bar\");\n}\n",
|
||||
"a {\n color: 7;\n}\n"
|
||||
);
|
||||
test!(
|
||||
str_len_double_wide,
|
||||
"a {\n color: str-length(\"👭\");\n}\n",
|
||||
"@charset \"UTF-8\";\na {\n color: 1;\n}\n"
|
||||
);
|
||||
test!(
|
||||
str_len_combining,
|
||||
"a {\n color: str-length(\"c\\0308\");\n}\n",
|
||||
"a {\n color: 2;\n}\n"
|
||||
);
|
||||
test!(
|
||||
str_index_char,
|
||||
"a {\n color: str-index(abcd, a);\n}\n",
|
||||
|
Loading…
x
Reference in New Issue
Block a user