Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6725:f0f6cec0ac46 HEAD
Lone CR handling fixes.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 08 Nov 2007 02:26:58 +0200 |
parents | 76fc7245e74b |
children | 1a551d95ac9c |
files | src/lib/istream-crlf.c src/tests/test-istream.c |
diffstat | 2 files changed, 27 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/istream-crlf.c Thu Nov 08 01:59:05 2007 +0200 +++ b/src/lib/istream-crlf.c Thu Nov 08 02:26:58 2007 +0200 @@ -99,6 +99,7 @@ const unsigned char *data; size_t i, dest, size; ssize_t ret; + int diff; ret = i_stream_crlf_read_common(cstream); if (ret <= 0) @@ -124,13 +125,22 @@ stream->w_buffer[dest++] = data[0]; } + diff = -1; for (i = 1; i < size && dest < stream->buffer_size; i++) { - if (data[i] == '\r' && data[i-1] != '\r') - continue; + if (data[i] == '\r') { + if (data[i-1] != '\r') + continue; + } else if (data[i-1] == '\r' && data[i] != '\n') { + stream->w_buffer[dest++] = '\r'; + if (dest == stream->buffer_size) { + diff = 0; + break; + } + } stream->w_buffer[dest++] = data[i]; } - cstream->pending_cr = data[i-1] == '\r'; + cstream->pending_cr = data[i+diff] == '\r'; i_stream_skip(cstream->input, i); ret = dest - stream->pos;
--- a/src/tests/test-istream.c Thu Nov 08 01:59:05 2007 +0200 +++ b/src/tests/test-istream.c Thu Nov 08 02:26:58 2007 +0200 @@ -17,11 +17,11 @@ output = t_str_new(256); - for (j = 0; j < 2; j++) { + for (j = 0; j < 4; j++) { istream = i_stream_create_from_data(input, input_len); success = TRUE; str_truncate(output, 0); - if (j == 0) { + if (j%2 == 0) { /* drop CRs */ crlf_istream = i_stream_create_lf(istream); for (i = 0; i < input_len; i++) { @@ -44,6 +44,16 @@ pos = 0; for (i = 1; i <= input_len; i++) { + if (j >= 2) { + i_stream_unref(&istream); + i_stream_unref(&crlf_istream); + istream = i_stream_create_from_data(input, + input_len); + crlf_istream = j%2 == 0 ? + i_stream_create_lf(istream) : + i_stream_create_crlf(istream); + pos = 0; + } istream->real_stream->pos = i; if (crlf_istream->real_stream->buffer_size != 0) { /* this is pretty evil */ @@ -69,7 +79,7 @@ i_stream_unref(&crlf_istream); i_stream_unref(&istream); - test_out(t_strdup_printf("test_istream_crlf(%d)", num*2+j), + test_out(t_strdup_printf("test_istream_crlf(%d)", num*4+j), success); } } @@ -77,8 +87,8 @@ static void test_istream_crlf(void) { const char *input[] = { + "\rfoo", "foo\nbar\r\nbaz\r\r\n", - "\rfoo", "\r\nfoo", "\r\r\n", "\nfoo"