1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-24 13:33:01 +03:00

html: Don't escape RAWTEXT and PLAINTEXT

Align with HTML5.
This commit is contained in:
Nick Wellnhofer
2025-04-12 23:10:40 +02:00
parent 809ded586b
commit 05b8fe0a06
3 changed files with 19 additions and 14 deletions

View File

@@ -499,13 +499,6 @@ htmlSkipBlankChars(xmlParserCtxtPtr ctxt) {
* Name,Start Tag,End Tag,Save End,Empty,Deprecated,DTD,inline,Description
*/
#define DATA_RCDATA 1
#define DATA_RAWTEXT 2
#define DATA_PLAINTEXT 3
#define DATA_SCRIPT 4
#define DATA_SCRIPT_ESC1 5
#define DATA_SCRIPT_ESC2 6
static const htmlElemDesc
html40ElementTable[] = {
{ "a", 0, 0, 0, 0, 0, 0, 1, "anchor ",

View File

@@ -24,6 +24,7 @@
#include <libxml/uri.h>
#include "private/buf.h"
#include "private/html.h"
#include "private/error.h"
#include "private/html.h"
#include "private/io.h"
@@ -714,6 +715,7 @@ htmlNodeDumpInternal(xmlOutputBufferPtr buf, xmlNodePtr cur,
xmlNodePtr root, parent, metaHead = NULL;
xmlAttrPtr attr;
const htmlElemDesc * info;
int isRaw = 0;
xmlInitParser();
@@ -873,6 +875,10 @@ htmlNodeDumpInternal(xmlOutputBufferPtr buf, xmlNodePtr cur,
(cur->children->type != HTML_ENTITY_REF_NODE))
xmlOutputBufferWrite(buf, 1, "\n");
}
if ((info != NULL) && (info->dataMode >= DATA_RAWTEXT))
isRaw = 1;
parent = cur;
cur = cur->children;
continue;
@@ -898,14 +904,11 @@ htmlNodeDumpInternal(xmlOutputBufferPtr buf, xmlNodePtr cur,
case HTML_TEXT_NODE:
if (cur->content == NULL)
break;
if (((cur->name == (const xmlChar *)xmlStringText) ||
(cur->name != (const xmlChar *)xmlStringTextNoenc)) &&
((parent == NULL) ||
((xmlStrcasecmp(parent->name, BAD_CAST "script")) &&
(xmlStrcasecmp(parent->name, BAD_CAST "style"))))) {
xmlSerializeText(buf, cur->content, XML_ESCAPE_HTML);
} else {
if ((cur->name == (const xmlChar *)xmlStringTextNoenc) ||
(isRaw)) {
xmlOutputBufferWriteString(buf, (const char *)cur->content);
} else {
xmlSerializeText(buf, cur->content, XML_ESCAPE_HTML);
}
break;
@@ -954,6 +957,8 @@ htmlNodeDumpInternal(xmlOutputBufferPtr buf, xmlNodePtr cur,
break;
}
isRaw = 0;
cur = parent;
/* cur->parent was validated when descending. */
parent = cur->parent;

View File

@@ -9,6 +9,13 @@
(((c) == 0x20) || \
(((c) >= 0x09) && ((c) <= 0x0D) && ((c) != 0x0B)))
#define DATA_RCDATA 1
#define DATA_RAWTEXT 2
#define DATA_PLAINTEXT 3
#define DATA_SCRIPT 4
#define DATA_SCRIPT_ESC1 5
#define DATA_SCRIPT_ESC2 6
typedef struct {
size_t start;
size_t end;