mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-24 02:03:06 -05:00
LibWeb: Calculate length for all CharacterData
type nodes correctly
We now ensure that `Node::is_character_data()` returns true for all nodes of type character data. Previously, calling `Node::length()` on `CDataSection` or `ProcessingInstruction` nodes would return an incorrect value.
This commit is contained in:
parent
f8b1e96e2b
commit
3802d9ccc4
Notes:
github-actions[bot]
2024-07-25 14:58:20 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/3802d9ccc4e Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/798 Reviewed-by: https://github.com/AtkinsSJ ✅ Reviewed-by: https://github.com/trflynn89
3 changed files with 14 additions and 1 deletions
|
@ -0,0 +1 @@
|
|||
range start offset: 0, end offset: 3
|
|
@ -0,0 +1,11 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
const xmlDocument = new DOMParser().parseFromString(`<xml></xml>`, "application/xml");
|
||||
const cdata = xmlDocument.createCDATASection("DATA");
|
||||
const range = xmlDocument.createRange();
|
||||
range.setStart(cdata, 0);
|
||||
range.setEnd(cdata, 3);
|
||||
println(`range start offset: ${range.startOffset}, end offset: ${range.endOffset}`);
|
||||
});
|
||||
</script>
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <AK/Badge.h>
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/GenericShorthands.h>
|
||||
#include <AK/JsonObjectSerializer.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/TypeCasts.h>
|
||||
|
@ -69,7 +70,7 @@ public:
|
|||
bool is_document() const { return type() == NodeType::DOCUMENT_NODE; }
|
||||
bool is_document_type() const { return type() == NodeType::DOCUMENT_TYPE_NODE; }
|
||||
bool is_comment() const { return type() == NodeType::COMMENT_NODE; }
|
||||
bool is_character_data() const { return type() == NodeType::TEXT_NODE || type() == NodeType::COMMENT_NODE; }
|
||||
bool is_character_data() const { return first_is_one_of(type(), NodeType::TEXT_NODE, NodeType::COMMENT_NODE, NodeType::CDATA_SECTION_NODE, NodeType::PROCESSING_INSTRUCTION_NODE); }
|
||||
bool is_document_fragment() const { return type() == NodeType::DOCUMENT_FRAGMENT_NODE; }
|
||||
bool is_parent_node() const { return is_element() || is_document() || is_document_fragment(); }
|
||||
bool is_slottable() const { return is_element() || is_text() || is_cdata_section(); }
|
||||
|
|
Loading…
Add table
Reference in a new issue