1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-31 06:50:06 +03:00

SAX2: Don't merge CDATA sections

The Document Object Model (DOM) Level 3 Core Specification says:

> Adjacent CDATASection nodes are not merged by use of the normalize
> method of the Node interface.

Fixes #412.
This commit is contained in:
Nick Wellnhofer 2024-08-29 00:07:27 +02:00
parent dde62ae5d5
commit 8ae06d5223
9 changed files with 40 additions and 1 deletions

2
SAX2.c
View File

@ -2471,7 +2471,7 @@ xmlSAX2Text(xmlParserCtxtPtr ctxt, const xmlChar *ch, int len,
} else {
int coalesceText = (lastChild != NULL) &&
(lastChild->type == type) &&
((type != XML_TEXT_NODE) ||
(((ctxt->html) && (type != XML_TEXT_NODE)) ||
(lastChild->name == xmlStringText));
if ((coalesceText) && (ctxt->nodemem != 0)) {
int maxLength = (ctxt->options & XML_PARSE_HUGE) ?

View File

@ -0,0 +1,2 @@
<?xml version="1.0"?>
<doc><![CDATA[abc]]><![CDATA[def]]><![CDATA[ghi]]></doc>

View File

@ -0,0 +1,5 @@
0 1 doc 0 0
1 4 #cdata-section 0 1 abc
1 4 #cdata-section 0 1 def
1 4 #cdata-section 0 1 ghi
0 15 doc 0 0

View File

@ -0,0 +1,5 @@
0 1 doc 0 0
1 4 #cdata-section 0 1 abc
1 4 #cdata-section 0 1 def
1 4 #cdata-section 0 1 ghi
0 15 doc 0 0

View File

@ -0,0 +1,8 @@
SAX.setDocumentLocator()
SAX.startDocument()
SAX.startElement(doc)
SAX.pcdata(abc, 3)
SAX.pcdata(def, 3)
SAX.pcdata(ghi, 3)
SAX.endElement(doc)
SAX.endDocument()

View File

@ -0,0 +1,8 @@
SAX.setDocumentLocator()
SAX.startDocument()
SAX.startElementNs(doc, NULL, NULL, 0, 0, 0)
SAX.pcdata(abc, 3)
SAX.pcdata(def, 3)
SAX.pcdata(ghi, 3)
SAX.endElementNs(doc, NULL, NULL)
SAX.endDocument()

View File

@ -0,0 +1,2 @@
<?xml version="1.0"?>
<doc><![CDATA[abc]]><![CDATA[def]]><![CDATA[ghi]]></doc>

View File

@ -0,0 +1,8 @@
SAX.setDocumentLocator()
SAX.startDocument()
SAX.startElementNs(doc, NULL, NULL, 0, 0, 0)
SAX.pcdata(abc, 3)
SAX.pcdata(def, 3)
SAX.pcdata(ghi, 3)
SAX.endElementNs(doc, NULL, NULL)
SAX.endDocument()

1
test/adjacent-cdata.xml Normal file
View File

@ -0,0 +1 @@
<doc><![CDATA[abc]]><![CDATA[def]]><![CDATA[ghi]]></doc>