Strip spaces at end of header lines (Zarafa).

This commit is contained in:
Vincent Richard 2013-03-24 15:50:16 +01:00
parent 21945be4c4
commit 32eb1ebe34
2 changed files with 32 additions and 1 deletions

View File

@ -142,7 +142,7 @@ ref <headerField> headerField::parseNext
++pos; ++pos;
const string::size_type contentsStart = pos; const string::size_type contentsStart = pos;
string::size_type contentsEnd = end; string::size_type contentsEnd = 0;
// Extract the field value // Extract the field value
while (pos < end) 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 // Return a new field
ref <headerField> field = headerFieldFactory::getInstance()->create(name); ref <headerField> field = headerFieldFactory::getInstance()->create(name);

View File

@ -29,6 +29,7 @@ VMIME_TEST_SUITE_BEGIN(headerFieldTest)
VMIME_TEST_LIST_BEGIN VMIME_TEST_LIST_BEGIN
VMIME_TEST(testBadValueType) VMIME_TEST(testBadValueType)
VMIME_TEST(testValueOnNextLine) VMIME_TEST(testValueOnNextLine)
VMIME_TEST(testStripSpacesAtEnd)
VMIME_TEST_LIST_END VMIME_TEST_LIST_END
@ -66,4 +67,20 @@ VMIME_TEST_SUITE_BEGIN(headerFieldTest)
VASSERT_EQ("Field value", "field data", hvalue->getWholeBuffer()); 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 VMIME_TEST_SUITE_END