1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-08-06 21:49:23 +03:00

html: Don't escape < and > when serializing attribute values

Align with HTML5.

This will break some test suites.
This commit is contained in:
Nick Wellnhofer
2025-05-09 23:02:32 +02:00
parent e0e0a1f0f5
commit cdaf657ffb
6 changed files with 13 additions and 21 deletions

View File

@ -611,18 +611,21 @@ xmlEscapeText(const xmlChar *text, int flags) {
xmlChar *out;
const xmlChar *unescaped;
size_t size = 50;
int isHtmlAttr = 0;
buffer = xmlMalloc(size + 1);
if (buffer == NULL)
return(NULL);
out = buffer;
if ((flags & XML_ESCAPE_HTML) && (flags & XML_ESCAPE_ATTR))
isHtmlAttr = 1;
cur = text;
unescaped = cur;
while (*cur != '\0') {
char buf[12];
const xmlChar *end;
const xmlChar *repl;
size_t used;
size_t replSize;
@ -649,21 +652,10 @@ xmlEscapeText(const xmlChar *text, int flags) {
chunkSize = 0;
repl = BAD_CAST "";
replSize = 0;
} else if (c == '<') {
/*
* Special handling of server side include in HTML attributes
*/
if ((flags & XML_ESCAPE_HTML) && (flags & XML_ESCAPE_ATTR) &&
(cur[1] == '!') && (cur[2] == '-') && (cur[3] == '-') &&
((end = xmlStrstr(cur, BAD_CAST "-->")) != NULL)) {
chunkSize = (end - cur) + 3;
repl = cur;
replSize = chunkSize;
} else {
repl = BAD_CAST "&lt;";
replSize = 4;
}
} else if (c == '>') {
} else if ((c == '<') && (!isHtmlAttr)) {
repl = BAD_CAST "&lt;";
replSize = 4;
} else if ((c == '>') && (!isHtmlAttr)) {
repl = BAD_CAST "&gt;";
replSize = 4;
} else if (c == '&') {

View File

@ -3,6 +3,6 @@
<body>
<a href="index.cgi?a&amp;lt=1&amp;gt=2">link</a>
<a href="index.cgi?a&amp;lta&amp;gta">link</a>
<a href="index.cgi?a&lt;&gt;">link</a>
<a href="index.cgi?a<>">link</a>
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta name="Author" content="Root &lt;root@aol.com&gt;">
<meta name="Author" content="Root <root@aol.com>">
</head>
</html>

View File

@ -5,6 +5,6 @@
<script language="javascript">
if (window.open<max) ;
</script>
<input onclick="if(window.open&lt;max);">
<input onclick="if(window.open<max);">
</body>
</html>

View File

@ -43,7 +43,7 @@
درباره من </a></span> <span class="Item">
<a href="RSS2.asp">
<img src="showimage.aspx?path=Files_Upload\192.png&amp;width=%&gt;" border="0">
<img src="showimage.aspx?path=Files_Upload\192.png&amp;width=%>" border="0">
RSS </a></span> <span class="Item">
<a href="">
</a></span>