aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/headerField.cpp16
-rw-r--r--tests/parser/headerFieldTest.cpp17
2 files changed, 32 insertions, 1 deletions
diff --git a/src/headerField.cpp b/src/headerField.cpp
index 7d23ce84..1d33dac1 100644
--- a/src/headerField.cpp
+++ b/src/headerField.cpp
@@ -142,7 +142,7 @@ ref <headerField> headerField::parseNext
++pos;
const string::size_type contentsStart = pos;
- string::size_type contentsEnd = end;
+ string::size_type contentsEnd = 0;
// Extract the field value
while (pos < end)
@@ -215,6 +215,20 @@ ref <headerField> headerField::parseNext
}
}
+ if (pos == end && contentsEnd == 0)
+ {
+ // End of data, and no CRLF was found at the end
+ contentsEnd = end;
+ }
+
+ // Strip spaces from end of header lines
+ while (contentsEnd > contentsStart &&
+ (buffer[contentsEnd - 1] == ' ' || buffer[contentsEnd - 1] == '\t' ||
+ buffer[contentsEnd - 1] == '\r' || buffer[contentsEnd - 1] == '\n'))
+ {
+ contentsEnd--;
+ }
+
// Return a new field
ref <headerField> field = headerFieldFactory::getInstance()->create(name);
diff --git a/tests/parser/headerFieldTest.cpp b/tests/parser/headerFieldTest.cpp
index 9d8f9dfa..b551c781 100644
--- a/tests/parser/headerFieldTest.cpp
+++ b/tests/parser/headerFieldTest.cpp
@@ -29,6 +29,7 @@ VMIME_TEST_SUITE_BEGIN(headerFieldTest)
VMIME_TEST_LIST_BEGIN
VMIME_TEST(testBadValueType)
VMIME_TEST(testValueOnNextLine)
+ VMIME_TEST(testStripSpacesAtEnd)
VMIME_TEST_LIST_END
@@ -66,4 +67,20 @@ VMIME_TEST_SUITE_BEGIN(headerFieldTest)
VASSERT_EQ("Field value", "field data", hvalue->getWholeBuffer());
}
+ void testStripSpacesAtEnd()
+ {
+ vmime::parsingContext ctx;
+
+ const vmime::string buffer = "Field: \r\n\tfield data ";
+
+ vmime::ref <vmime::headerField> hfield =
+ vmime::headerField::parseNext(ctx, buffer, 0, buffer.size());
+
+ vmime::ref <vmime::text> hvalue =
+ hfield->getValue().dynamicCast <vmime::text>();
+
+ VASSERT_EQ("Field name", "Field", hfield->getName());
+ VASSERT_EQ("Field value", toHex("field data"), toHex(hvalue->getWholeBuffer()));
+ }
+
VMIME_TEST_SUITE_END