~singpolyma/biboumi

7d8ce3b5638b8e09313a6218014a307ab98e6289 — Florent Le Coz 10 years ago 3960e4d
Use XML-sanitized strings when serializing stanzas for the XMPP server
2 files changed, 12 insertions(+), 3 deletions(-)

M src/test.cpp
M src/xmpp/xmpp_stanza.cpp
M src/test.cpp => src/test.cpp +8 -0
@@ 97,6 97,14 @@ int main()
      });
  xml.feed(doc.data(), doc.size(), true);

  const std::string doc2 = "<stream xmlns='s'><stanza>coucou\r\n\a</stanza></stream>";
  xml.add_stanza_callback([](const Stanza& stanza)
      {
        std::cout << stanza.to_string() << std::endl;
        assert(stanza.get_inner() == "coucou\r\n");
      });
  xml.feed(doc2.data(), doc.size(), true);

  /**
   * XML escape/escape
   */

M src/xmpp/xmpp_stanza.cpp => src/xmpp/xmpp_stanza.cpp +4 -3
@@ 192,12 192,13 @@ std::string XmlNode::to_string() const
  std::string res("<");
  res += this->name;
  for (const auto& it: this->attributes)
    res += " " + it.first + "='" + it.second + "'";
    res += " " + utils::remove_invalid_xml_chars(it.first) + "='" +
      utils::remove_invalid_xml_chars(it.second) + "'";
  if (this->closed && !this->has_children() && this->inner.empty())
    res += "/>";
  else
    {
      res += ">" + this->inner;
      res += ">" + utils::remove_invalid_xml_chars(this->inner);
      for (const auto& child: this->children)
        res += child->to_string();
      if (this->closed)


@@ 205,7 206,7 @@ std::string XmlNode::to_string() const
          res += "</" + this->name + ">";
        }
    }
  res += this->tail;
  res += utils::remove_invalid_xml_chars(this->tail);
  return res;
}