diff --git a/ChangeLog b/ChangeLog index 4f3728955..812a10660 100644 --- a/ChangeLog +++ b/ChangeLog @@ -41,6 +41,8 @@ (thanks to Itay Perl). + Fixed bug #579, which displayed incorrect counts when using the 'limit:N' filter (thanks to Thomas Sattler). + + Applied patch to fix bug #581, in which backslashes in annotations and + descriptions caused problems (thanks to Itay Perl). ------ old releases ------------------------------ diff --git a/src/Nibbler.cpp b/src/Nibbler.cpp index 4514e59d0..13bb7ee7b 100644 --- a/src/Nibbler.cpp +++ b/src/Nibbler.cpp @@ -213,66 +213,51 @@ bool Nibbler::getUntilEOS (std::string& result) bool Nibbler::getQuoted ( char c, std::string& result, - bool unescape /* = true */, bool quote /* = false */) { - if (mCursor < mLength) + bool inquote = false; + bool inescape = false; + char current = 0; + char previous = 0; + result = ""; + + if (mCursor >= mLength || + mInput[mCursor] != c) { - if (mInput[mCursor] != c) - return false; + return false; + } - result = ""; - bool inquote = false; - char current = 0; - char previous = 0; + for (std::string::size_type i = mCursor; i < mLength; ++i) + { + previous = current; + current = mInput[i]; - // '"' - // p c - // - - - // ' - // ' " - // " ' - for (std::string::size_type i = mCursor; i < mLength; ++i) + if (current == '\\' && !inescape) { - previous = current; - current = mInput[i]; + inescape = true; + continue; + } - if (current == c) + if (current == c && !inescape) + { + if (quote) + result += current; + + if (!inquote) { - if (previous == '\\') - { - if (!unescape) - result += previous; - - result += current; - } - else - { - if (!inquote) - { - inquote = true; - if (quote) - result += current; - } - else - { - if (quote) - result += current; - - mCursor = i + 1; - return true; - } - } - } - else if (current == '\\') - { - // NOP + inquote = true; } else { - result += current; + mCursor = i + 1; + return true; } } + else + { + result += current; + inescape = false; + } } return false; diff --git a/src/Nibbler.h b/src/Nibbler.h index 7c69348ef..1834d9649 100644 --- a/src/Nibbler.h +++ b/src/Nibbler.h @@ -47,7 +47,7 @@ public: bool getUntilEOL (std::string&); bool getUntilEOS (std::string&); - bool getQuoted (char, std::string&, bool unescape = true, bool quote = false); + bool getQuoted (char, std::string&, bool quote = false); bool getInt (int&); bool getUnsignedInt (int&); bool getNumber (double&); diff --git a/src/tests/att.t.cpp b/src/tests/att.t.cpp index 6445dff3f..b147dcf2d 100644 --- a/src/tests/att.t.cpp +++ b/src/tests/att.t.cpp @@ -258,13 +258,13 @@ int main (int argc, char** argv) n = Nibbler ("name:\""\""); a7.parse (n); - t.is (a7.composeF4 (), "name:\"&dquot;\"", - "Att::parse (name:\""\")"); + t.is (a7.composeF4 (), "name:\"'\"", + "Att::parse (name:\"'\")"); n = Nibbler ("name:\"&tab;",&open;&close;:\""); a7.parse (n); - t.is (a7.composeF4 (), "name:\"&tab;&dquot;,&open;&close;:\"", - "Att::parse (name:\"&tab;",&open;&close;:\")"); + t.is (a7.composeF4 (), "name:\"&tab;',&open;&close;:\"", + "Att::parse (name:\"&tab;',&open;&close;:\")"); n = Nibbler ("total gibberish"); good = true; diff --git a/src/tests/nibbler.t.cpp b/src/tests/nibbler.t.cpp index 9107a2533..f4a72be26 100644 --- a/src/tests/nibbler.t.cpp +++ b/src/tests/nibbler.t.cpp @@ -190,23 +190,23 @@ int main (int argc, char** argv) t.notok (n.getQuoted ('\'', s), " 'x' : getQuoted (''') -> false"); n = Nibbler ("\"one\\\"two\""); - t.notok (n.getQuoted ('\'', s), "\"one\\\"two\" : getQuoted (''') -> false"); // 86 + t.notok (n.getQuoted ('\'', s), "\"one\\\"two\" : getQuoted (''') -> false"); // 86 n = Nibbler ("\"one\\\"two\""); - t.ok (n.getQuoted ('"', s, false, false), "\"one\\\"two\" : getQuoted ('\"', false, false) -> true"); // 87 - t.is (s, "one\\\"two", "getQuoted ('\"', false, false) -> one\\\"two"); // 88 + t.ok (n.getQuoted ('"', s, false), "\"one\\\"two\" : getQuoted ('\"', false, false) -> true"); // 87 + t.is (s, "one\"two", "getQuoted ('\"', false) -> one\"two"); // 88 n = Nibbler ("\"one\\\"two\""); - t.ok (n.getQuoted ('"', s, false, true), "\"one\\\"two\" : getQuoted ('\"', false, true) -> true"); // 89 - t.is (s, "\"one\\\"two\"", "getQuoted ('\"', false, true) -> \"one\\\"two\""); // 90 + t.ok (n.getQuoted ('"', s, true), "\"one\\\"two\" : getQuoted ('\"', false, true) -> true"); // 89 + t.is (s, "\"one\"two\"", "getQuoted ('\"', true) -> \"one\"two\""); // 90 n = Nibbler ("\"one\\\"two\""); - t.ok (n.getQuoted ('"', s, true, false), "\"one\\\"two\" : getQuoted ('\"', true, false) -> true"); // 91 - t.is (s, "one\"two", "getQuoted ('\"', true, false) -> one\"two"); // 92 + t.ok (n.getQuoted ('"', s, false), "\"one\\\"two\" : getQuoted ('\"', true, false) -> true"); // 91 + t.is (s, "one\"two", "getQuoted ('\"', false) -> one\"two"); // 92 n = Nibbler ("\"one\\\"two\""); - t.ok (n.getQuoted ('"', s, true, true), "\"one\\\"two\" : getQuoted ('\"', true, true) -> true"); // 93 - t.is (s, "\"one\"two\"", "getQuoted ('\"', true, true) -> \"one\"two\""); // 94 + t.ok (n.getQuoted ('"', s, true), "\"one\\\"two\" : getQuoted ('\"', true, true) -> true"); // 93 + t.is (s, "\"one\"two\"", "getQuoted ('\"', true) -> \"one\"two\""); // 94 // bool getInt (int&);