mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-06 09:26:17 +01:00
Merge branch 'data-input-stream-read-line-utf8-fix' into 'main'
gdatainputstream: Fix length return value on UTF-8 validation failure See merge request GNOME/glib!4348
This commit is contained in:
commit
a8dbd7cad5
@ -840,7 +840,11 @@ g_data_input_stream_read_line_utf8 (GDataInputStream *stream,
|
||||
g_set_error_literal (error, G_CONVERT_ERROR,
|
||||
G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
|
||||
_("Invalid byte sequence in conversion input"));
|
||||
|
||||
if (length != NULL)
|
||||
*length = 0;
|
||||
g_free (res);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
return res;
|
||||
|
@ -80,9 +80,9 @@ test_read_lines (GDataStreamNewlineType newline_type)
|
||||
lines[i] = "some_text";
|
||||
|
||||
base_stream = g_memory_input_stream_new ();
|
||||
g_assert (base_stream != NULL);
|
||||
g_assert_nonnull (base_stream);
|
||||
stream = G_INPUT_STREAM (g_data_input_stream_new (base_stream));
|
||||
g_assert(stream != NULL);
|
||||
g_assert_nonnull (stream);
|
||||
|
||||
/* Byte order testing */
|
||||
g_data_input_stream_set_byte_order (G_DATA_INPUT_STREAM (stream), G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN);
|
||||
@ -174,8 +174,17 @@ test_read_lines_LF_valid_utf8 (void)
|
||||
gsize length = -1;
|
||||
line = g_data_input_stream_read_line_utf8 (G_DATA_INPUT_STREAM (stream), &length, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
if (line == NULL)
|
||||
break;
|
||||
{
|
||||
g_assert_cmpuint (length, ==, 0);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_assert_cmpuint (length, >, 0);
|
||||
}
|
||||
|
||||
n_lines++;
|
||||
g_free (line);
|
||||
}
|
||||
@ -207,11 +216,16 @@ test_read_lines_LF_invalid_utf8 (void)
|
||||
gsize length = -1;
|
||||
line = g_data_input_stream_read_line_utf8 (G_DATA_INPUT_STREAM (stream), &length, NULL, &error);
|
||||
if (n_lines == 0)
|
||||
g_assert_no_error (error);
|
||||
{
|
||||
/* First line is valid UTF-8 */
|
||||
g_assert_no_error (error);
|
||||
g_assert_cmpuint (length, ==, 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_assert (error != NULL);
|
||||
g_assert_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE);
|
||||
g_clear_error (&error);
|
||||
g_assert_cmpuint (length, ==, 0);
|
||||
g_free (line);
|
||||
break;
|
||||
}
|
||||
@ -354,7 +368,7 @@ test_read_upto (void)
|
||||
line++;
|
||||
|
||||
stop_char = g_data_input_stream_read_byte (G_DATA_INPUT_STREAM (stream), NULL, &error);
|
||||
g_assert (memchr (DATA_SEP, stop_char, DATA_SEP_LEN) != NULL);
|
||||
g_assert_nonnull (memchr (DATA_SEP, stop_char, DATA_SEP_LEN));
|
||||
g_assert_no_error (error);
|
||||
}
|
||||
g_free (data);
|
||||
|
Loading…
Reference in New Issue
Block a user