Issue #168: multiple sequences of 'LF..' not replaced correctly.

This commit is contained in:
Vincent Richard 2017-03-28 22:31:04 +02:00
parent 041854731c
commit 604b713562
2 changed files with 20 additions and 20 deletions

View File

@ -86,28 +86,17 @@ size_t dotFilteredInputStream::read(byte_t* const data, const size_t count)
size_t written = 0;
byte_t prevChar2 = m_previousChar2;
byte_t prevChar1 = m_previousChar1;
// Replace "\n.." with "\n."
while (readPtr < end)
{
if (*readPtr == '.')
if (*readPtr == '.' && prevChar2 == '\n' && prevChar1 == '.')
{
const byte_t prevChar2 =
(readPtr == data + 1 ? m_previousChar1 :
readPtr == data ? m_previousChar2 : *(readPtr - 2));
const byte_t prevChar1 =
(readPtr == data ? m_previousChar1 : *(readPtr - 1));
if (prevChar2 == '\n' && prevChar1 == '.')
{
// Ignore last dot
}
else
{
*writePtr = *readPtr;
++writePtr;
++written;
}
// Ignore last dot
prevChar2 = '\0';
prevChar1 = '.';
}
else
{
@ -115,13 +104,16 @@ size_t dotFilteredInputStream::read(byte_t* const data, const size_t count)
++writePtr;
++written;
prevChar2 = prevChar1;
prevChar1 = *readPtr;
}
++readPtr;
}
m_previousChar2 = (read >= 2 ? data[read - 2] : m_previousChar1);
m_previousChar1 = (read >= 1 ? data[read - 1] : '\0');
m_previousChar2 = prevChar2;
m_previousChar1 = prevChar1;
return (written);
}

View File

@ -128,6 +128,12 @@ VMIME_TEST_SUITE_BEGIN(filteredStreamTest)
testDotFilteredInputStreamHelper("4", "foo\n.bar", "foo\n..", "bar");
testDotFilteredInputStreamHelper("5", "foo\n.bar", "foo\n", ".", ".bar");
testDotFilteredInputStreamHelper("6", "foo\n.bar", "foo\n", ".", ".", "bar");
testDotFilteredInputStreamHelper("7", "\x0d\x0a.", "\x0d\x0a..");
testDotFilteredInputStreamHelper("8", "\x0d\x0a.\x0d\x0a", "\x0d\x0a..\x0d\x0a");
testDotFilteredInputStreamHelper("9", "\x0d\x0a.\x0d\x0a.", "\x0d\x0a..\x0d\x0a.");
testDotFilteredInputStreamHelper("10", "\x0d\x0a.\x0d\x0a.\x0d\x0ax", "\x0d\x0a..\x0d\x0a.\x0d\x0ax");
testDotFilteredInputStreamHelper("11", "this is the first line\x0d\x0a.\x0d\x0aone dot\x0d\x0a..\x0d\x0atwo dots\x0d\x0a...\x0d\x0athree... \x0d\x0a.\x0d\x0a.\x0d\x0a", "this is the first line\x0d\x0a..\x0d\x0aone dot\x0d\x0a...\x0d\x0atwo dots\x0d\x0a....\x0d\x0athree... \x0d\x0a..\x0d\x0a.\x0d\x0a");
}
// dotFilteredOutputStream
@ -167,6 +173,8 @@ VMIME_TEST_SUITE_BEGIN(filteredStreamTest)
testFilteredOutputStreamHelper<FILTER>("8", "..\r\nfoobar", ".\r", "\nfoobar");
testFilteredOutputStreamHelper<FILTER>("9", ".foobar", ".foobar");
testFilteredOutputStreamHelper<FILTER>("10", ".foobar", ".", "foobar");
testFilteredOutputStreamHelper<FILTER>("11", "this is the first line\x0d\x0a...\x0d\x0aone dot\x0d\x0a....\x0d\x0atwo dots\x0d\x0a.....\x0d\x0athree... \x0d\x0a...\x0d\x0a..\x0d\x0a", "this is the first line\x0d\x0a..\x0d\x0aone dot\x0d\x0a...\x0d\x0atwo dots\x0d\x0a....\x0d\x0athree... \x0d\x0a..\x0d\x0a.\x0d\x0a");
}
void testCRLFToLFFilteredOutputStream()