diff options
author | albert-github <albert.tests@gmail.com> | 2019-01-06 11:31:51 (GMT) |
---|---|---|
committer | albert-github <albert.tests@gmail.com> | 2019-01-06 11:31:51 (GMT) |
commit | a53d5b44731b55197d7ff2ae046552374d011e59 (patch) | |
tree | a1ae128f2c331230f7be24db5704a8f3cb46fe85 /src | |
parent | de34e6c26eeb0dca1b1a6aa8bf26d21bb3fd644f (diff) | |
download | Doxygen-a53d5b44731b55197d7ff2ae046552374d011e59.zip Doxygen-a53d5b44731b55197d7ff2ae046552374d011e59.tar.gz Doxygen-a53d5b44731b55197d7ff2ae046552374d011e59.tar.bz2 |
issue #6744 Ampersand in Markdown image URL is not escaped in XML output
Convert name / url based on HTML / XML conventions and don't do double conversions (XML).
Diffstat (limited to 'src')
-rw-r--r-- | src/htmldocvisitor.cpp | 4 | ||||
-rw-r--r-- | src/util.cpp | 27 | ||||
-rw-r--r-- | src/util.h | 2 | ||||
-rw-r--r-- | src/xmldocvisitor.cpp | 6 |
4 files changed, 30 insertions, 9 deletions
diff --git a/src/htmldocvisitor.cpp b/src/htmldocvisitor.cpp index 8c78f85..9f9e653 100644 --- a/src/htmldocvisitor.cpp +++ b/src/htmldocvisitor.cpp @@ -1584,7 +1584,7 @@ void HtmlDocVisitor::visitPre(DocHRef *href) else { QCString url = correctURL(href->url(),href->relPath()); - m_t << "<a href=\"" << convertToXML(url) << "\"" + m_t << "<a href=\"" << convertToHtml(url) << "\"" << htmlAttribsToString(href->attribs()) << ">"; } } @@ -1668,7 +1668,7 @@ void HtmlDocVisitor::visitPre(DocImage *img) } else { - m_t << "<img src=\"" << src << "\" alt=\"" << alt << "\"" << sizeAttribs << attrs; + m_t << "<img src=\"" << convertToHtml(src) << "\" alt=\"" << alt << "\"" << sizeAttribs << attrs; if (inlineImage) { m_t << " class=\"inline\""; diff --git a/src/util.cpp b/src/util.cpp index 24e8898..f9c2492 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -5914,7 +5914,7 @@ QCString convertToId(const char *s) } /*! Converts a string to an XML-encoded string */ -QCString convertToXML(const char *s) +QCString convertToXML(const char *s, bool keepEntities) { static GrowBuf growBuf; growBuf.clear(); @@ -5927,7 +5927,30 @@ QCString convertToXML(const char *s) { case '<': growBuf.addStr("<"); break; case '>': growBuf.addStr(">"); break; - case '&': growBuf.addStr("&"); break; + case '&': if (keepEntities) + { + const char *e=p; + char ce; + while ((ce=*e++)) + { + if (ce==';' || (!(isId(ce) || ce=='#'))) break; + } + if (ce==';') // found end of an entity + { + // copy entry verbatim + growBuf.addChar(c); + while (p<e) growBuf.addChar(*p++); + } + else + { + growBuf.addStr("&"); + } + } + else + { + growBuf.addStr("&"); + } + break; case '\'': growBuf.addStr("'"); break; case '"': growBuf.addStr("""); break; case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: @@ -284,7 +284,7 @@ QCString convertToHtml(const char *s,bool keepEntities=TRUE); QCString convertToLaTeX(const QCString &s,bool insideTabbing=FALSE,bool keepSpaces=FALSE); -QCString convertToXML(const char *s); +QCString convertToXML(const char *s, bool keepEntities=FALSE); QCString convertToDocBook(const char *s); diff --git a/src/xmldocvisitor.cpp b/src/xmldocvisitor.cpp index e464088..01e0a6d 100644 --- a/src/xmldocvisitor.cpp +++ b/src/xmldocvisitor.cpp @@ -60,7 +60,7 @@ static void visitPreStart(FTextStream &t, const char *cmd, bool doCaption, } if (!name.isEmpty()) { - t << " name=\"" << name << "\""; + t << " name=\"" << convertToXML(name, TRUE) << "\""; } if (!width.isEmpty()) { @@ -770,9 +770,7 @@ void XmlDocVisitor::visitPost(DocInternal *) void XmlDocVisitor::visitPre(DocHRef *href) { if (m_hide) return; - m_t << "<ulink url=\""; - filter(href->url()); - m_t << "\">"; + m_t << "<ulink url=\"" << convertToXML(href->url(), TRUE) << "\">"; } void XmlDocVisitor::visitPost(DocHRef *) |