diff --git a/src/Mod/TechDraw/App/DrawUtil.cpp b/src/Mod/TechDraw/App/DrawUtil.cpp
index 2132f30ca6..a062c06e2a 100644
--- a/src/Mod/TechDraw/App/DrawUtil.cpp
+++ b/src/Mod/TechDraw/App/DrawUtil.cpp
@@ -851,7 +851,37 @@ int DrawUtil::countSubShapes(TopoDS_Shape shape, TopAbs_ShapeEnum subShape)
return count;
}
-
+//https://stackoverflow.com/questions/5665231/most-efficient-way-to-escape-xml-html-in-c-string
+//for every character in inoutText, check if it is on the list of characters to be substituted and
+//replace it with the encoding string
+void DrawUtil::encodeXmlSpecialChars(std::string& inoutText)
+{
+ std::string buffer;
+ buffer.reserve(inoutText.size());
+ for(size_t cursor = 0; cursor != inoutText.size(); ++cursor) {
+ switch(inoutText.at(cursor)) {
+ case '&':
+ buffer.append("&");
+ break;
+ case '\"':
+ buffer.append(""");
+ break;
+ case '\'':
+ buffer.append("'");
+ break;
+ case '<':
+ buffer.append("<");
+ break;
+ case '>':
+ buffer.append(">");
+ break;
+ default:
+ buffer.append(&inoutText.at(cursor), 1); //not a special character
+ break;
+ }
+ }
+ inoutText.swap(buffer);
+}
// Supplementary mathematical functions
// ====================================
diff --git a/src/Mod/TechDraw/App/DrawUtil.h b/src/Mod/TechDraw/App/DrawUtil.h
index 26549a3669..90070cae45 100644
--- a/src/Mod/TechDraw/App/DrawUtil.h
+++ b/src/Mod/TechDraw/App/DrawUtil.h
@@ -123,6 +123,7 @@ class TechDrawExport DrawUtil {
static Base::Vector3d getFaceCenter(TopoDS_Face f);
static bool circulation(Base::Vector3d A, Base::Vector3d B, Base::Vector3d C);
static int countSubShapes(TopoDS_Shape shape, TopAbs_ShapeEnum subShape);
+ static void encodeXmlSpecialChars(std::string& inoutText);
// Supplementary mathematical functions
diff --git a/src/Mod/TechDraw/App/DrawViewSpreadsheet.cpp b/src/Mod/TechDraw/App/DrawViewSpreadsheet.cpp
index 68202f2f2d..197fe1334a 100644
--- a/src/Mod/TechDraw/App/DrawViewSpreadsheet.cpp
+++ b/src/Mod/TechDraw/App/DrawViewSpreadsheet.cpp
@@ -42,6 +42,7 @@
#include
#include "Preferences.h"
+#include "DrawUtil.h"
#include "DrawViewSpreadsheet.h"
#include
@@ -284,13 +285,17 @@ std::string DrawViewSpreadsheet::getSheetImage(void)
std::stringstream field;
if (prop && cell) {
if (prop->isDerivedFrom((App::PropertyQuantity::getClassTypeId()))) {
- field << cell->getFormattedQuantity();
+ std::string temp = cell->getFormattedQuantity(); //writable
+ DrawUtil::encodeXmlSpecialChars(temp);
+ field << temp;
} else if (prop->isDerivedFrom((App::PropertyFloat::getClassTypeId()))) {
field << cell->getFormattedQuantity();
} else if (prop->isDerivedFrom((App::PropertyInteger::getClassTypeId()))) {
field << cell->getFormattedQuantity();
} else if (prop->isDerivedFrom((App::PropertyString::getClassTypeId()))) {
- field << static_cast(prop)->getValue();
+ std::string temp = static_cast(prop)->getValue();
+ DrawUtil::encodeXmlSpecialChars(temp);
+ field << temp;
} else {
Base::Console().Error("DVSS: Unknown property type\n");
celltext = "???";