mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 12:44:43 +00:00
prorper escaping of null character
This commit is contained in:
@@ -69,3 +69,11 @@
|
|||||||
testing.expectEqual(true, CSS.supports('z-index', '10'));
|
testing.expectEqual(true, CSS.supports('z-index', '10'));
|
||||||
}
|
}
|
||||||
</script>
|
</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>
|
||||||
|
|||||||
@@ -141,16 +141,16 @@ fn hexDigitsNeeded(c: u8) usize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn writeEscape(comptime is_first: bool, buf: []u8, 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] = '\\';
|
buf[0] = '\\';
|
||||||
var data = buf[1..];
|
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')) {
|
if (isHexEscape(c) or ((comptime is_first) and c >= '0' and c <= '9')) {
|
||||||
const hex_str = std.fmt.bufPrint(data, "{x} ", .{c}) catch unreachable;
|
const hex_str = std.fmt.bufPrint(data, "{x} ", .{c}) catch unreachable;
|
||||||
return 1 + hex_str.len;
|
return 1 + hex_str.len;
|
||||||
|
|||||||
Reference in New Issue
Block a user