Truly independent web browser
LibWeb: Accept non-negative signed indices in `env()`
Callum Law15cf256dd2f1
diff --git a/Libraries/LibWeb/Rust/src/css/custom_properties.rs b/Libraries/LibWeb/Rust/src/css/custom_properties.rsindex 44c3cff900c..ed08718f8b8 100644--- a/Libraries/LibWeb/Rust/src/css/custom_properties.rs+++ b/Libraries/LibWeb/Rust/src/css/custom_properties.rs@@ -1738,11 +1738,10 @@ fn replace_env_function(if !matches!(token.kind, OwnedTokenKind::Number) {return None;}- let source = token.source.to_vec();- let index = source.iter().try_fold(0i32, |value, &unit| {- let digit = unit.checked_sub(u16::from(b'0'))?;- (digit <= 9).then_some(value.checked_mul(10)?.checked_add(i32::from(digit))?)- })?;+ let index = String::from_utf16_lossy(&token.source.to_vec())+ .parse::<i32>()+ .ok()+ .filter(|index| *index >= 0)?;indices.push(index);}Some(indices)diff --git a/Tests/LibWeb/Text/expected/css/env-signed-indices.txt b/Tests/LibWeb/Text/expected/css/env-signed-indices.txtnew file mode 100644index 00000000000..1a718d61c84--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/env-signed-indices.txt@@ -0,0 +1,3 @@+20px+20px+30pxdiff --git a/Tests/LibWeb/Text/input/css/env-signed-indices.html b/Tests/LibWeb/Text/input/css/env-signed-indices.htmlnew file mode 100644index 00000000000..1e1b3680833--- /dev/null+++ b/Tests/LibWeb/Text/input/css/env-signed-indices.html@@ -0,0 +1,11 @@+<!doctype html>+<div id="target" style="width: attr(data-value type(<length>), 30px)"></div>+<script src="../include.js"></script>+<script>+ test(() => {+ for (const index of ["+1", "-0", "-1"]) {+ target.setAttribute("data-value", `env(unknown ${index}, 20px)`);+ println(getComputedStyle(target).width);+ }+ });+</script>