Bug 1375400 - Handle single \r line end more gracefully. r=jorgk,aceman
--- a/mailnews/base/util/nsMsgMailNewsUrl.cpp
+++ b/mailnews/base/util/nsMsgMailNewsUrl.cpp
@@ -914,24 +914,19 @@ NS_IMETHODIMP nsMsgSaveAsListener::OnDat
m_dataBuffer[m_leftOver] = '\0';
start = m_dataBuffer;
// make sure we don't insert another LF, accidentally, by ignoring
// second half of CRLF spanning blocks.
if (lastCharInPrevBuf == '\r' && *start == '\n')
start++;
- end = PL_strchr(start, '\r');
- if (!end)
- end = PL_strchr(start, '\n');
- else if (*(end+1) == '\n' && linebreak_len == 0)
- linebreak_len = 2;
-
- if (linebreak_len == 0) // not initialize yet
- linebreak_len = 1;
+ end = PL_strpbrk(start, "\r\n");
+ if (end)
+ linebreak_len = (end[0] == '\r' && end[1] == '\n') ? 2 : 1;
count -= readCount;
maxReadCount = SAVE_BUF_SIZE - m_leftOver;
if (!end && count > maxReadCount)
// must be a very very long line; sorry cannot handle it
return NS_ERROR_FAILURE;
@@ -950,19 +945,19 @@ NS_IMETHODIMP nsMsgSaveAsListener::OnDat
}
start = end+linebreak_len;
if (start >= m_dataBuffer + m_leftOver)
{
maxReadCount = SAVE_BUF_SIZE;
m_leftOver = 0;
break;
}
- end = PL_strchr(start, '\r');
- if (!end)
- end = PL_strchr(start, '\n');
+ end = PL_strpbrk(start, "\r\n");
+ if (end)
+ linebreak_len = (end[0] == '\r' && end[1] == '\n') ? 2 : 1;
if (start && !end)
{
m_leftOver -= (start - m_dataBuffer);
memcpy(m_dataBuffer, start,
m_leftOver+1); // including null
maxReadCount = SAVE_BUF_SIZE - m_leftOver;
}
}