aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/vmime/utility/filteredStream.cpp32
-rw-r--r--tests/utility/filteredStreamTest.cpp8
2 files changed, 20 insertions, 20 deletions
diff --git a/src/vmime/utility/filteredStream.cpp b/src/vmime/utility/filteredStream.cpp
index d745b384..99ba13fd 100644
--- a/src/vmime/utility/filteredStream.cpp
+++ b/src/vmime/utility/filteredStream.cpp
@@ -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);
}
diff --git a/tests/utility/filteredStreamTest.cpp b/tests/utility/filteredStreamTest.cpp
index ec1fc66a..cedfab2a 100644
--- a/tests/utility/filteredStreamTest.cpp
+++ b/tests/utility/filteredStreamTest.cpp
@@ -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()