[gnote] Fix XmlEncoder::encode()



commit ab93567fe9afc0d5ab6cde038d90100d5bed7180
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Sun Nov 20 18:52:32 2011 +0200

    Fix XmlEncoder::encode()
    
    It didn't actually encoded text to XML.

 src/utils.cpp |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/src/utils.cpp b/src/utils.cpp
index 0f5dd77..693412f 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -525,10 +525,19 @@ namespace gnote {
     std::string XmlEncoder::encode(const std::string & source)
     {
       sharp::XmlWriter xml;
+      //need element so that source is properly escaped
+      xml.write_start_element("", "x", "");
       xml.write_string(source);
+      xml.write_end_element();
 
       xml.close();
-      return xml.to_string();
+      std::string result = xml.to_string();
+      unsigned end_pos = result.find("</x>");
+      if(end_pos == result.npos) {
+        return "";
+      }
+      result.resize(end_pos);
+      return result.substr(3);
     }
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]