summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Monnerat <[email protected]>2015-07-10 17:33:48 +0200
committerinfirit <[email protected]>2015-09-02 11:34:01 +0200
commitf6d7a422f3f5f97e676cd18cef5bb46aca8da6be (patch)
tree9e747796bb93ac6a292e11eadedcad1092895d1a
parentbdfc07a804d787bdee7ec671bcc397517de3de7c (diff)
downloadpluma-f6d7a422f3f5f97e676cd18cef5bb46aca8da6be.tar.bz2
pluma-f6d7a422f3f5f97e676cd18cef5bb46aca8da6be.tar.xz
Fix issue#100: CRLF across 8k boundary inserts an empty line.
-rw-r--r--pluma/pluma-document-output-stream.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/pluma/pluma-document-output-stream.c b/pluma/pluma-document-output-stream.c
index 06aa728d..df1f58c9 100644
--- a/pluma/pluma-document-output-stream.c
+++ b/pluma/pluma-document-output-stream.c
@@ -290,7 +290,6 @@ pluma_document_output_stream_write (GOutputStream *stream,
gsize len;
gboolean freetext = FALSE;
const gchar *end;
- gsize nvalid;
gboolean valid;
if (g_cancellable_set_error_if_cancelled (cancellable, error))
@@ -328,16 +327,22 @@ pluma_document_output_stream_write (GOutputStream *stream,
/* validate */
valid = g_utf8_validate (text, len, &end);
- nvalid = end - text;
+
+ /* Avoid keeping a CRLF across two buffers. */
+ if (valid && len > 1 && end[-1] == '\r') {
+ valid = FALSE;
+ end--;
+ }
if (!valid)
{
- gsize remainder;
-
- remainder = len - nvalid;
+ gsize nvalid = end - text;
+ gsize remainder = len - nvalid;
+ gunichar ch;
if ((remainder < MAX_UNICHAR_LEN) &&
- (g_utf8_get_char_validated (text + nvalid, remainder) == (gunichar)-2))
+ ((ch = g_utf8_get_char_validated (text + nvalid, remainder)) == (gunichar)-2 ||
+ ch == (gunichar)'\r'))
{
ostream->priv->buffer = g_strndup (end, remainder);
ostream->priv->buflen = remainder;
@@ -345,7 +350,7 @@ pluma_document_output_stream_write (GOutputStream *stream,
}
else
{
- /* TODO: we cuould escape invalid text and tag it in red
+ /* TODO: we could escape invalid text and tag it in red
* and make the doc readonly.
*/
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,