Merge pull request #1704 from lightpanda-io/non-ascii-css-key
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
e2e-test / browser fetch (push) Has been cancelled
zig-test / zig test using v8 in debug mode (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled

css: fix crash in consumeName() on UTF-8 multibyte sequences
This commit is contained in:
Pierre Tachoire
2026-03-04 12:35:14 +01:00
committed by GitHub
2 changed files with 24 additions and 4 deletions

View File

@@ -480,10 +480,11 @@ fn consumeName(self: *Tokenizer) []const u8 {
self.consumeEscape();
},
0x0 => self.advance(1),
'\x80'...'\xBF', '\xC0'...'\xEF', '\xF0'...'\xFF' => {
// This byte *is* part of a multi-byte code point,
// well end up copying the whole code point before this loop does something else.
self.advance(1);
'\x80'...'\xFF' => {
// Non-ASCII: advance over the complete UTF-8 code point in one step.
// Using consumeChar() instead of advance(1) ensures we never land on
// a continuation byte, which advance() asserts against.
self.consumeChar();
},
else => {
if (self.hasNonAsciiAt(0)) {

View File

@@ -256,3 +256,22 @@
testing.expectTrue(!html.includes('opacity:0'));
}
</script>
<script id="CSSStyleDeclaration_non_ascii_custom_property">
{
// Regression test: accessing element.style must not crash when the inline
// style attribute contains CSS custom properties with non-ASCII (UTF-8
// multibyte) names, such as French accented characters.
// The CSS Tokenizer's consumeName() must advance over whole UTF-8 sequences
// rather than byte-by-byte to avoid landing on a continuation byte.
const div = document.createElement('div');
div.setAttribute('style',
'--color-store-bulles-\u00e9t\u00e9-fg: #6a818f;' +
'--color-store-soir\u00e9es-odl-fg: #56b3b3;' +
'color: red;'
);
// Must not crash, and ASCII properties that follow non-ASCII ones must be readable.
testing.expectEqual('red', div.style.getPropertyValue('color'));
}
</script>