mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-23 22:58:00 -05:00
Correctly handle setting textContent to empty for DocFrag and Element
Fixes an [non-critical] error on old.reddit.com
This commit is contained in:
@@ -176,3 +176,16 @@
|
||||
testing.expectEqual("Nested content", clonedInner.textContent);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id=textContent>
|
||||
{
|
||||
const df = document.createDocumentFragment();
|
||||
df.appendChild(document.createElement("div"));
|
||||
testing.expectEqual(1, df.childNodes.length);
|
||||
df.textContent = '';
|
||||
testing.expectEqual(0, df.childNodes.length);
|
||||
|
||||
df.textContent = ' ';
|
||||
testing.expectEqual(1, df.childNodes.length);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -153,3 +153,16 @@
|
||||
testing.expectEqual(d, parent.childNodes[3]);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id=textContent>
|
||||
{
|
||||
const parent = document.createElement('div');
|
||||
parent.appendChild(document.createElement('div'));
|
||||
testing.expectEqual(1, parent.childNodes.length);
|
||||
parent.textContent = '';
|
||||
testing.expectEqual(0, parent.childNodes.length);
|
||||
|
||||
parent.textContent = ' ';
|
||||
testing.expectEqual(1, parent.childNodes.length);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -269,11 +269,21 @@ pub fn getTextContentAlloc(self: *Node, allocator: Allocator) error{WriteFailed}
|
||||
|
||||
pub fn setTextContent(self: *Node, data: []const u8, page: *Page) !void {
|
||||
switch (self._type) {
|
||||
.element => |el| return el.replaceChildren(&.{.{ .text = data }}, page),
|
||||
.element => |el| {
|
||||
if (data.len == 0) {
|
||||
return el.replaceChildren(&.{}, page);
|
||||
}
|
||||
return el.replaceChildren(&.{.{ .text = data }}, page);
|
||||
},
|
||||
.cdata => |c| c._data = try page.arena.dupe(u8, data),
|
||||
.document => {},
|
||||
.document_type => {},
|
||||
.document_fragment => |frag| return frag.replaceChildren(&.{.{ .text = data }}, page),
|
||||
.document_fragment => |frag| {
|
||||
if (data.len == 0) {
|
||||
return frag.replaceChildren(&.{}, page);
|
||||
}
|
||||
return frag.replaceChildren(&.{.{ .text = data }}, page);
|
||||
},
|
||||
.attribute => |attr| return attr.setValue(data, page),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user