summaryrefslogtreecommitdiff
path: root/src/core/XML.cpp
diff options
context:
space:
mode:
authorBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-01-13 11:26:20 +0100
committerBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-01-13 11:26:20 +0100
commit3311fa10fdd841a1b2d6146b848166f3da6e5487 (patch)
tree6da1f5822d2c6b52eb74fb78bc5f7af3b68c4bb3 /src/core/XML.cpp
parent83b034d47728a7519128b2777ac95fa0b558f882 (diff)
escaped attribute values in XML serialization.
Diffstat (limited to 'src/core/XML.cpp')
-rw-r--r--src/core/XML.cpp57
1 files changed, 29 insertions, 28 deletions
diff --git a/src/core/XML.cpp b/src/core/XML.cpp
index 9c23e3b..528e1cd 100644
--- a/src/core/XML.cpp
+++ b/src/core/XML.cpp
@@ -36,6 +36,33 @@ void Node::serialize(std::ostream &out, const std::string &doctype, bool pretty)
doSerialize(out, 0, pretty);
}
+static std::string escapePredefinedEntities(const std::string &input)
+{
+ std::stringstream ss;
+ for (const char &c : input) {
+ switch (c) {
+ case '<':
+ ss << "&lt;";
+ break;
+ case '>':
+ ss << "&gt;";
+ break;
+ case '&':
+ ss << "&amp;";
+ break;
+ case '\'':
+ ss << "&apos;";
+ break;
+ case '\"':
+ ss << "&quot;";
+ break;
+ default:
+ ss << c;
+ }
+ }
+ return std::move(ss.str());
+}
+
void Element::doSerialize(std::ostream &out, unsigned int tabdepth, bool pretty)
{
if (pretty) {
@@ -45,7 +72,8 @@ void Element::doSerialize(std::ostream &out, unsigned int tabdepth, bool pretty)
}
out << '<' << name;
for (auto &a : attributes) {
- out << ' ' << a.first << "=\"" << a.second << '\"';
+ out << ' ' << a.first << "=\"" << escapePredefinedEntities(a.second)
+ << '\"';
}
// if we have no children, we close the tag immediately.
if (children.size() == 0) {
@@ -73,33 +101,6 @@ void Element::doSerialize(std::ostream &out, unsigned int tabdepth, bool pretty)
}
}
-static std::string escapePredefinedEntities(const std::string &input)
-{
- std::stringstream ss;
- for (const char &c : input) {
- switch (c) {
- case '<':
- ss << "&lt;";
- break;
- case '>':
- ss << "&gt;";
- break;
- case '&':
- ss << "&amp;";
- break;
- case '\'':
- ss << "&apos;";
- break;
- case '\"':
- ss << "&quot;";
- break;
- default:
- ss << c;
- }
- }
- return std::move(ss.str());
-}
-
void Text::doSerialize(std::ostream &out, unsigned int tabdepth, bool pretty)
{
if (pretty) {