mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-30 11:27:19 +02:00
Bug #581
- Applied patch to fix bug #581, in which backslashes in annotations and descriptions caused problems (thanks to Itay Perl). - Corrected unit tests that were shown to be incorrect, after the patch corrected other behavior.
This commit is contained in:
parent
1d4c79b897
commit
595dd9f3f4
5 changed files with 48 additions and 61 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue