Merge pull request #1615 from lightpanda-io/css_escape_null
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
nightly build / build-linux-x86_64 (push) Has been cancelled
nightly build / build-linux-aarch64 (push) Has been cancelled
nightly build / build-macos-aarch64 (push) Has been cancelled
nightly build / build-macos-x86_64 (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
e2e-integration-test / zig build release (push) Has been cancelled
e2e-integration-test / demo-integration-scripts (push) Has been cancelled

prorper escaping of null character
This commit is contained in:
Pierre Tachoire
2026-02-20 15:38:54 +01:00
committed by GitHub
2 changed files with 15 additions and 7 deletions

View File

@@ -69,3 +69,11 @@
testing.expectEqual(true, CSS.supports('z-index', '10'));
}
</script>
<script id="escape_null_character">
{
testing.expectEqual('\uFFFD', CSS.escape('\x00'));
testing.expectEqual('test\uFFFDvalue', CSS.escape('test\x00value'));
testing.expectEqual('\uFFFDabc', CSS.escape('\x00abc'));
}
</script>

View File

@@ -141,16 +141,16 @@ fn hexDigitsNeeded(c: u8) usize {
}
fn writeEscape(comptime is_first: bool, buf: []u8, c: u8) usize {
if (c == 0) {
// NULL character becomes replacement character (no backslash)
const replacement = "\u{FFFD}";
@memcpy(buf[0..replacement.len], replacement);
return replacement.len;
}
buf[0] = '\\';
var data = buf[1..];
if (c == 0) {
// NULL character becomes replacement character
const replacement = "\u{FFFD}";
@memcpy(data[0..replacement.len], replacement);
return 1 + replacement.len;
}
if (isHexEscape(c) or ((comptime is_first) and c >= '0' and c <= '9')) {
const hex_str = std.fmt.bufPrint(data, "{x} ", .{c}) catch unreachable;
return 1 + hex_str.len;