>From 1d5e1378e49ee8fde8f7accffff3451c6993d2fe Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin
Date: Thu, 27 Aug 2015 20:08:51 +0200 Subject: [PATCH] Escape special characters in group quotes report to preserve them in HTML. Avoid possible data loss in or corruption of the generated report if any special XML characters occurred in any fields inserted into it. --- group_quote_pdf_gen_wx.cpp | 47 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/group_quote_pdf_gen_wx.cpp b/group_quote_pdf_gen_wx.cpp index bb769d6..3148ae7 100644 --- a/group_quote_pdf_gen_wx.cpp +++ b/group_quote_pdf_gen_wx.cpp @@ -63,6 +63,35 @@ enum enum_output_mode ,e_output_measure_only }; +/// Escape special XML characters in the given string, ensuring that it appears +/// correctly inside HTML element contents. Notice that we don't need to escape +/// quotes here as we never use the result of this function inside an HTML +/// attribute, only inside HTML elements. + +wxString escape_for_html_elem(std::string const& s) +{ + wxString esc; + esc.reserve(s.length()); + for(std::string::const_iterator ci = s.begin(); ci != s.end(); ++ci) + { + switch(*ci) + { + case '<': + esc += "<"; + break; + case '>': + esc += ">"; + break; + case '&': + esc += "&"; + break; + default: + esc += *ci; + } + } + return esc; +} + /// Load the image from the given file. Throw on failure. wxImage load_image(char const* file) @@ -731,9 +760,9 @@ void group_quote_pdf_generator_wx::do_generate_pdf(wxPdfDC& pdf_dc) "" + report_data_.footer_ + "
"; + wxString const footer_html = "" + escape_for_html_elem(report_data_.footer_) + "
"; *pos_y += output_html (html_parser -- 2.1.0