regex: Fix unicode othercasing
authorChristian Persch <chpe@gnome.org>
Sun, 17 Jun 2012 20:51:44 +0000 (22:51 +0200)
committerChristian Persch <chpe@gnome.org>
Mon, 2 Jul 2012 13:59:39 +0000 (15:59 +0200)
Reorder the toupper/tolower calls when othercaseing, so this
function is bug-for-bug compatible with the pcre internal tables.

https://bugzilla.gnome.org/show_bug.cgi?id=678273

glib/pcre/pcre_tables.c
glib/tests/regex.c

index 5bac855..ddbf950 100644 (file)
@@ -589,10 +589,10 @@ _pcre_ucp_othercase(const unsigned int c)
 {
   unsigned int oc;
 
-  if ((oc = g_unichar_tolower(c)) != c)
-    return oc;
   if ((oc = g_unichar_toupper(c)) != c)
     return oc;
+  if ((oc = g_unichar_tolower(c)) != c)
+    return oc;
 
   return c;
 }
index a155e3a..72a0155 100644 (file)
@@ -2332,6 +2332,12 @@ main (int argc, char *argv[])
   /* This failed with PCRE 7.2 (gnome bug #455640) */
   TEST_MATCH(".*$", 0, 0, "\xe1\xbb\x85", -1, 0, 0, TRUE);
 
+  /* Test that othercasing in our pcre/glib integration is bug-for-bug compatible
+   * with pcre's internal tables. Bug #678273 */
+  TEST_MATCH("[DŽ]", G_REGEX_CASELESS, 0, "DŽ", -1, 0, 0, TRUE);
+  TEST_MATCH("[DŽ]", G_REGEX_CASELESS, 0, "Dž", -1, 0, 0, FALSE);
+  TEST_MATCH("[DŽ]", G_REGEX_CASELESS, 0, "dž", -1, 0, 0, TRUE);
+
   /* TEST_MATCH_NEXT#(pattern, string, string_len, start_position, ...) */
   TEST_MATCH_NEXT0("a", "x", -1, 0);
   TEST_MATCH_NEXT0("a", "ax", -1, 1);