[nemiver/el6-branch] 657834 Properly un-escape '\"' sequence



commit aca7d1aded9da0681ddec185d8630f0417f93be1
Author: Dodji Seketeli <dodji seketeli org>
Date:   Fri Sep 2 14:06:35 2011 +0200

    657834 Properly un-escape '\"' sequence
    
    	* src/dbgengine/nmv-gdbmi-parser.cc:
    	(GDBMIParser::parse_c_string_body):  Properly handle '\"' escape
    	sequence of characters.
    	* tests/test-gdbmi.cc: (test_str4):  Add new test case, and ...
    	(init_unit_test_suite): ... wire it.

 src/dbgengine/nmv-gdbmi-parser.cc |    9 +++++++--
 tests/test-gdbmi.cc               |   19 +++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/src/dbgengine/nmv-gdbmi-parser.cc b/src/dbgengine/nmv-gdbmi-parser.cc
index 8dcf6a5..379f112 100644
--- a/src/dbgengine/nmv-gdbmi-parser.cc
+++ b/src/dbgengine/nmv-gdbmi-parser.cc
@@ -728,8 +728,13 @@ GDBMIParser::parse_c_string_body (UString::size_type a_from,
         if (isascii (ch)) {
             if (ch == '"' && prev_ch != '\\') {
                 break;
-            }
-            if (ch == '\\') {
+            } else if (ch == '"' && prev_ch == '\\') {
+                // So '"' was escaped as '\"'.  Let's expand it into
+                // '"'.
+                result.erase (result.end () - 1);
+                result += ch;
+                ++cur;
+            } else if (ch == '\\') {
                 UString seq;
                 if (!m_priv->index_passed_end (cur+3)
                     && isdigit (RAW_CHAR_AT (cur +1))
diff --git a/tests/test-gdbmi.cc b/tests/test-gdbmi.cc
index ffbcaf7..1a12a4e 100644
--- a/tests/test-gdbmi.cc
+++ b/tests/test-gdbmi.cc
@@ -14,6 +14,7 @@ static const char* gv_str0 = "\"abracadabra\"";
 static const char* gv_str1 = "\"/home/dodji/misc/no\\303\\253l-\\303\\251-\\303\\240/test.c\"";
 static const char* gv_str2 = "\"No symbol \\\"events_ecal\\\" in current context.\\n\"";
 static const char* gv_str3 = "\"Reading symbols from /home/dodji/devel/tests/ÃÃÃ/test...\"";
+static const char* gv_str4 = "\"\\\"Eins\\\"\"";
 static const char* gv_attrs0 = "msg=\"No symbol \\\"g_return_if_fail\\\" in current context.\"";
 static const char* gv_attrs1 = "script=[\"silent\",\"return\"]";
 
@@ -243,6 +244,23 @@ test_str3 ()
 }
 
 void
+test_str4 ()
+{
+    bool is_ok =false;
+
+    UString res;
+    UString::size_type to=0;
+
+    GDBMIParser parser (gv_str4);
+    is_ok = parser.parse_c_string (0, to, res);
+
+    BOOST_REQUIRE (is_ok);
+    MESSAGE ("got string: '" << Glib::locale_from_utf8 (res) << "'");
+    BOOST_REQUIRE_MESSAGE (res == "\"Eins\"", "res was: " << res);
+}
+
+
+void
 test_attr0 ()
 {
     bool is_ok =false;
@@ -962,6 +980,7 @@ init_unit_test_suite (int argc, char **argv)
     suite->add (BOOST_TEST_CASE (&test_str1));
     suite->add (BOOST_TEST_CASE (&test_str2));
     suite->add (BOOST_TEST_CASE (&test_str3));
+    suite->add (BOOST_TEST_CASE (&test_str4));
     suite->add (BOOST_TEST_CASE (&test_attr0));
     suite->add (BOOST_TEST_CASE (&test_stoppped_async_output));
     suite->add (BOOST_TEST_CASE (&test_running_async_output));



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