Bug 456053 - Don't trim trailing space of quoted lines. r=masayuki

This commit is contained in:
Jorg K 2016-09-29 07:10:00 +02:00
Родитель d30aa0e08b
Коммит cadd291ee3
3 изменённых файлов: 48 добавлений и 2 удалений

Просмотреть файл

@ -1582,7 +1582,7 @@ nsPlainTextSerializer::Write(const nsAString& aStr)
// that does normal formatted text. The one for preformatted text calls
// Output directly while the other code path goes through AddToLine.
if ((mPreFormattedMail && !mWrapColumn) || (IsInPre() && !mPreFormattedMail)
|| (mSpanLevel > 0 && mEmptyLines >= 0 && str.First() == char16_t('>'))) {
|| (mSpanLevel > 0 && mEmptyLines >= 0 && IsQuotedLine(str))) {
// No intelligent wrapping.
// This mustn't be mixed with intelligent wrapping without clearing
@ -1657,10 +1657,11 @@ nsPlainTextSerializer::Write(const nsAString& aStr)
mCurrentLine.Truncate();
if (mFlags & nsIDocumentEncoder::OutputFormatFlowed) {
if ((outputLineBreak || !spacesOnly) && // bugs 261467,125928
!IsQuotedLine(stringpart) &&
!stringpart.EqualsLiteral("-- ") &&
!stringpart.EqualsLiteral("- -- "))
stringpart.Trim(" ", false, true, true);
if (IsSpaceStuffable(stringpart.get()) && stringpart[0] != '>')
if (IsSpaceStuffable(stringpart.get()) && !IsQuotedLine(stringpart))
mCurrentLine.Append(char16_t(' '));
}
mCurrentLine.Append(stringpart);

Просмотреть файл

@ -110,6 +110,11 @@ private:
return mHeadLevel == 0;
}
inline bool IsQuotedLine(const nsAString& aLine)
{
return !aLine.IsEmpty() && aLine.First() == char16_t('>');
}
// Stack handling functions
bool GetLastBool(const nsTArray<bool>& aStack);
void SetLastBool(nsTArray<bool>& aStack, bool aValue);

Просмотреть файл

@ -130,6 +130,43 @@ TestCJKWithDisallowLineBreaking()
return NS_OK;
}
// Test for ASCII with format=flowed; and quoted lines in preformatted span.
nsresult
TestPreformatFlowedQuotes()
{
nsString test;
nsString result;
test.AssignLiteral("<html><body>"
"<span style=\"white-space: pre-wrap;\">"
"&gt; Firefox Firefox Firefox Firefox <br>"
"&gt; Firefox Firefox Firefox Firefox<br>"
"&gt;<br>"
"&gt;&gt; Firefox Firefox Firefox Firefox <br>"
"&gt;&gt; Firefox Firefox Firefox Firefox<br>"
"</span></body></html>");
ConvertBufToPlainText(test, nsIDocumentEncoder::OutputFormatted |
nsIDocumentEncoder::OutputCRLineBreak |
nsIDocumentEncoder::OutputLFLineBreak |
nsIDocumentEncoder::OutputFormatFlowed);
// create result case
result.AssignLiteral("> Firefox Firefox Firefox Firefox \r\n"
"> Firefox Firefox Firefox Firefox\r\n"
">\r\n"
">> Firefox Firefox Firefox Firefox \r\n"
">> Firefox Firefox Firefox Firefox\r\n");
if (!test.Equals(result)) {
fail("Wrong HTML to ASCII text serialization with format=flowed; and quoted lines");
return NS_ERROR_FAILURE;
}
passed("HTML to ASCII text serialization with format=flowed; and quoted lines");
return NS_OK;
}
nsresult
TestPrettyPrintedHtml()
{
@ -267,6 +304,9 @@ TestPlainTextSerializer()
rv = TestCJKWithDisallowLineBreaking();
NS_ENSURE_SUCCESS(rv, rv);
rv = TestPreformatFlowedQuotes();
NS_ENSURE_SUCCESS(rv, rv);
// Add new tests here...
return NS_OK;
}