diff options
author | Edwin Mons <edwin.mons@isode.com> | 2019-02-07 12:35:02 (GMT) |
---|---|---|
committer | Edwin Mons <edwin.mons@isode.com> | 2019-02-07 12:50:49 (GMT) |
commit | 2fba2e9743e680b76c070a3604f5d6b56eb44e49 (patch) | |
tree | a0dc15670fa653a5e9f201319e2ad7fed3afb3df /Swiften/Serializer/XML/XMLElement.cpp | |
parent | 256d1392b0d45ffeac44f764297ea31d65cb0229 (diff) | |
download | swift-2fba2e9743e680b76c070a3604f5d6b56eb44e49.zip swift-2fba2e9743e680b76c070a3604f5d6b56eb44e49.tar.bz2 |
Split out attribute escape routine
Test-Information:
Unit tests pass on Debian 9
Change-Id: I60f95816cfa48a619f83daac1d88e229bbe228ed
Diffstat (limited to 'Swiften/Serializer/XML/XMLElement.cpp')
-rw-r--r-- | Swiften/Serializer/XML/XMLElement.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/Swiften/Serializer/XML/XMLElement.cpp b/Swiften/Serializer/XML/XMLElement.cpp index f2397ca..7515061 100644 --- a/Swiften/Serializer/XML/XMLElement.cpp +++ b/Swiften/Serializer/XML/XMLElement.cpp @@ -39,14 +39,17 @@ std::string XMLElement::serialize() { return result; } +std::string XMLElement::escapeAttributeValue(std::string value) { + String::replaceAll(value, '&', "&"); + String::replaceAll(value, '<', "<"); + String::replaceAll(value, '>', ">"); + String::replaceAll(value, '\'', "'"); + String::replaceAll(value, '"', """); + return value; +} + void XMLElement::setAttribute(const std::string& attribute, const std::string& value) { - std::string escapedValue(value); - String::replaceAll(escapedValue, '&', "&"); - String::replaceAll(escapedValue, '<', "<"); - String::replaceAll(escapedValue, '>', ">"); - String::replaceAll(escapedValue, '\'', "'"); - String::replaceAll(escapedValue, '"', """); - attributes_[attribute] = escapedValue; + attributes_[attribute] = escapeAttributeValue(value); } void XMLElement::addNode(std::shared_ptr<XMLNode> node) { |