From 9dda10ae7204179d0be80b4bd0c64642bf9a5eb4 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Sat, 16 Feb 2008 12:09:48 +0000 Subject: [PATCH] Fixed an XML parsing error for complex URLs git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51836 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/richtext/richtextxml.cpp | 55 +++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/richtext/richtextxml.cpp b/src/richtext/richtextxml.cpp index e1d42d4647..8b914fb646 100644 --- a/src/richtext/richtextxml.cpp +++ b/src/richtext/richtextxml.cpp @@ -491,6 +491,59 @@ static void OutputStringEnt(wxOutputStream& stream, const wxString& str, OutputString(stream, str.Mid(last, i - last), convMem, convFile); } +static wxString AttributeToXML(const wxString& str) +{ + wxString str1; + size_t i, last, len; + wxChar c; + + len = str.Len(); + last = 0; + for (i = 0; i < len; i++) + { + c = str.GetChar(i); + + // Original code excluded "&" but we _do_ want to convert + // the ampersand beginning & because otherwise when read in, + // the original "&" becomes "&". + + if (c == wxT('<') || c == wxT('>') || c == wxT('"') || + (c == wxT('&') /* && (str.Mid(i+1, 4) != wxT("amp;")) */ )) + { + str1 += str.Mid(last, i - last); + switch (c) + { + case wxT('<'): + str1 += wxT("<"); + break; + case wxT('>'): + str1 += wxT(">"); + break; + case wxT('&'): + str1 += wxT("&"); + break; + case wxT('"'): + str1 += wxT("""); + break; + default: break; + } + last = i + 1; + } + else if (wxUChar(c) > 127) + { + str1 += str.Mid(last, i - last); + + wxString s(wxT("&#")); + s << (int) c; + s << wxT(";"); + str1 += s; + last = i + 1; + } + } + str1 += str.Mid(last, i - last); + return str1; +} + inline static void OutputIndentation(wxOutputStream& stream, int indent) { wxString str = wxT("\n"); @@ -930,7 +983,7 @@ wxString wxRichTextXMLHandler::CreateStyle(const wxTextAttr& attr, bool isPara) str << wxT(" characterstyle=\"") << wxString(attr.GetCharacterStyleName()) << wxT("\""); if (attr.HasURL()) - str << wxT(" url=\"") << attr.GetURL() << wxT("\""); + str << wxT(" url=\"") << AttributeToXML(attr.GetURL()) << wxT("\""); if (isPara) { -- 2.45.2