mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-27 07:56:14 +01:00
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:
commit
28c07dc966
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user