From 79cdf170d2ab6c5378cfbf61d5c8888a4c666190 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Mon, 28 Dec 2015 21:25:48 +0100 Subject: Use the configured encoding value when decoding received messages --- louloulibs/xmpp/xmpp_stanza.cpp | 16 ++++++++-------- louloulibs/xmpp/xmpp_stanza.hpp | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'louloulibs') diff --git a/louloulibs/xmpp/xmpp_stanza.cpp b/louloulibs/xmpp/xmpp_stanza.cpp index f247436..407e631 100644 --- a/louloulibs/xmpp/xmpp_stanza.cpp +++ b/louloulibs/xmpp/xmpp_stanza.cpp @@ -84,6 +84,14 @@ std::string xml_unescape(const std::string& data) return res; } +std::string sanitize(const std::string& data, const std::string& encoding) +{ + if (utils::is_valid_utf8(data.data())) + return xml_escape(utils::remove_invalid_xml_chars(data)); + else + return xml_escape(utils::remove_invalid_xml_chars(utils::convert_to_utf8(data, encoding.data()))); +} + XmlNode::XmlNode(const std::string& name, XmlNode* parent): parent(parent) { @@ -259,14 +267,6 @@ std::string& XmlNode::operator[](const std::string& name) return this->attributes[name]; } -std::string sanitize(const std::string& data) -{ - if (utils::is_valid_utf8(data.data())) - return xml_escape(utils::remove_invalid_xml_chars(data)); - else - return xml_escape(utils::remove_invalid_xml_chars(utils::convert_to_utf8(data, "ISO-8859-1"))); -} - std::ostream& operator<<(std::ostream& os, const XmlNode& node) { return os << node.to_string(); diff --git a/louloulibs/xmpp/xmpp_stanza.hpp b/louloulibs/xmpp/xmpp_stanza.hpp index bdc937f..77ab206 100644 --- a/louloulibs/xmpp/xmpp_stanza.hpp +++ b/louloulibs/xmpp/xmpp_stanza.hpp @@ -8,7 +8,7 @@ std::string xml_escape(const std::string& data); std::string xml_unescape(const std::string& data); -std::string sanitize(const std::string& data); +std::string sanitize(const std::string& data, const std::string& encoding = "ISO-8859-1"); /** * Represent an XML node. It has -- cgit v1.2.3