[PATCH] 657834 Properly un-escape '\"' sequence
- From: Dodji Seketeli <dodji seketeli org>
- To: Nemiver Development <nemiver-list gnome org>
- Subject: [PATCH] 657834 Properly un-escape '\"' sequence
- Date: Sat, 03 Sep 2011 01:06:25 +0200
Hello,
In this bug, the problem was that Nemiver was failing to properly
evaluate the result of the escaping of the quote character, e.g '\"'.
As a result, when pretty printing instances of std::string, we where
getting ugly things like \"foo\", for an instance of std::string which
contained the string "foo". With the fix below, we are now getting a
normal "foo" string (note how the character '\' disappeared).
Tested and applied to master and gtk2-branch.
commit 9da56d001b37321eebfce6e67bc04decf5b0710b
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.
diff --git a/src/dbgengine/nmv-gdbmi-parser.cc b/src/dbgengine/nmv-gdbmi-parser.cc
index 046d2be..3beb4d0 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));
--
Dodji
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]