Merge branch 'regex-do-not-assert-on-compile-error' into 'main'

gregex: Ensure we translate the errcode without asserting on G_REGEX_ERROR_COMPILE

Closes #2694

See merge request GNOME/glib!2821
This commit is contained in:
Philip Withnall 2022-07-15 11:26:55 +00:00
commit 28c07dc966
2 changed files with 19 additions and 2 deletions

View File

@ -476,8 +476,12 @@ translate_compile_error (gint *errcode, const gchar **errmsg)
* Note that there can be more PCRE errors with the same GRegexError
* and that some PCRE errors are useless for us.
*/
gint original_errcode = *errcode;
switch (*errcode)
*errcode = -1;
*errmsg = NULL;
switch (original_errcode)
{
case PCRE2_ERROR_END_BACKSLASH:
*errcode = G_REGEX_ERROR_STRAY_BACKSLASH;
@ -725,7 +729,7 @@ translate_compile_error (gint *errcode, const gchar **errmsg)
break;
}
g_assert (*errcode != 0);
g_assert (*errcode != -1);
g_assert (*errmsg != NULL);
}

View File

@ -2187,6 +2187,18 @@ pcre2_ge (guint64 major, guint64 minor)
return (pcre2_major > major) || (pcre2_major == major && pcre2_minor >= minor);
}
static void
test_compile_errors (void)
{
GRegex *regex;
GError *error = NULL;
regex = g_regex_new ("\\o{999}", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
g_assert_null (regex);
g_assert_error (error, G_REGEX_ERROR, G_REGEX_ERROR_COMPILE);
g_clear_error (&error);
}
int
main (int argc, char *argv[])
{
@ -2204,6 +2216,7 @@ main (int argc, char *argv[])
g_test_add_func ("/regex/multiline", test_multiline);
g_test_add_func ("/regex/explicit-crlf", test_explicit_crlf);
g_test_add_func ("/regex/max-lookbehind", test_max_lookbehind);
g_test_add_func ("/regex/compile-errors", test_compile_errors);
/* TEST_NEW(pattern, compile_opts, match_opts) */
G_GNUC_BEGIN_IGNORE_DEPRECATIONS