diff options
author | Daniel Veillard <veillard@src.gnome.org> | 2003-12-09 22:51:37 +0000 |
---|---|---|
committer | Daniel Veillard <veillard@src.gnome.org> | 2003-12-09 22:51:37 +0000 |
commit | 18ab8721ff3d009b64d23a372370fa997cdea682 (patch) | |
tree | b669f31bdb438a1318b957fd28a166fa68c6c641 /entities.c | |
parent | 10c08c7d064d24eb9f4c25301f3743dce7186529 (diff) | |
download | android_external_libxml2-18ab8721ff3d009b64d23a372370fa997cdea682.tar.gz android_external_libxml2-18ab8721ff3d009b64d23a372370fa997cdea682.tar.bz2 android_external_libxml2-18ab8721ff3d009b64d23a372370fa997cdea682.zip |
fixed an XML entites content serialization potentially triggered by
* entities.c: fixed an XML entites content serialization
potentially triggered by XInclude, see #126817
Daniel
Diffstat (limited to 'entities.c')
-rw-r--r-- | entities.c | 46 |
1 files changed, 44 insertions, 2 deletions
@@ -743,6 +743,48 @@ xmlCopyEntitiesTable(xmlEntitiesTablePtr table) { #endif /* LIBXML_TREE_ENABLED */ #ifdef LIBXML_OUTPUT_ENABLED + +/** + * xmlDumpEntityContent: + * @buf: An XML buffer. + * @content: The entity content. + * + * This will dump the quoted string value, taking care of the special + * treatment required by % + */ +static void +xmlDumpEntityContent(xmlBufferPtr buf, const xmlChar *content) { + if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return; + if (xmlStrchr(content, '%')) { + const xmlChar * base, *cur; + + xmlBufferCCat(buf, "\""); + base = cur = content; + while (*cur != 0) { + if (*cur == '"') { + if (base != cur) + xmlBufferAdd(buf, base, cur - base); + xmlBufferAdd(buf, BAD_CAST """, 6); + cur++; + base = cur; + } else if (*cur == '%') { + if (base != cur) + xmlBufferAdd(buf, base, cur - base); + xmlBufferAdd(buf, BAD_CAST "%", 6); + cur++; + base = cur; + } else { + cur++; + } + } + if (base != cur) + xmlBufferAdd(buf, base, cur - base); + xmlBufferCCat(buf, "\""); + } else { + xmlBufferWriteQuotedString(buf, content); + } +} + /** * xmlDumpEntityDecl: * @buf: An XML buffer. @@ -760,7 +802,7 @@ xmlDumpEntityDecl(xmlBufferPtr buf, xmlEntityPtr ent) { if (ent->orig != NULL) xmlBufferWriteQuotedString(buf, ent->orig); else - xmlBufferWriteQuotedString(buf, ent->content); + xmlDumpEntityContent(buf, ent->content); xmlBufferWriteChar(buf, ">\n"); break; case XML_EXTERNAL_GENERAL_PARSED_ENTITY: @@ -803,7 +845,7 @@ xmlDumpEntityDecl(xmlBufferPtr buf, xmlEntityPtr ent) { xmlBufferWriteCHAR(buf, ent->name); xmlBufferWriteChar(buf, " "); if (ent->orig == NULL) - xmlBufferWriteQuotedString(buf, ent->content); + xmlDumpEntityContent(buf, ent->content); else xmlBufferWriteQuotedString(buf, ent->orig); xmlBufferWriteChar(buf, ">\n"); |