core: Replace symbols with spaces when matching names in PotentialMatch
authorPhilip Withnall <philip@tecnocode.co.uk>
Mon, 25 Jun 2012 19:07:21 +0000 (20:07 +0100)
committerPhilip Withnall <philip@tecnocode.co.uk>
Mon, 25 Jun 2012 21:49:18 +0000 (22:49 +0100)
This allows, for example, “Alice Badger” and “alice.badger” to have a HIGH
match. This is a common situation when trying to pair up IM personas with
other personas.

This also includes a test case.

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

folks/potential-match.vala
tests/tracker/match-name.vala

index ee8e3fb..aab3341 100644 (file)
@@ -545,13 +545,6 @@ public class Folks.PotentialMatch : Object
           case UnicodeType.ENCLOSING_MARK:
             /* Ignore those */
             break;
-          case UnicodeType.PRIVATE_USE:
-          case UnicodeType.SURROGATE:
-          case UnicodeType.LOWERCASE_LETTER:
-          case UnicodeType.MODIFIER_LETTER:
-          case UnicodeType.OTHER_LETTER:
-          case UnicodeType.TITLECASE_LETTER:
-          case UnicodeType.UPPERCASE_LETTER:
           case UnicodeType.DECIMAL_NUMBER:
           case UnicodeType.LETTER_NUMBER:
           case UnicodeType.OTHER_NUMBER:
@@ -569,6 +562,16 @@ public class Folks.PotentialMatch : Object
           case UnicodeType.LINE_SEPARATOR:
           case UnicodeType.PARAGRAPH_SEPARATOR:
           case UnicodeType.SPACE_SEPARATOR:
+            /* Replace punctuation with spaces. */
+            retval[0] = ' ';
+            break;
+          case UnicodeType.PRIVATE_USE:
+          case UnicodeType.SURROGATE:
+          case UnicodeType.LOWERCASE_LETTER:
+          case UnicodeType.MODIFIER_LETTER:
+          case UnicodeType.OTHER_LETTER:
+          case UnicodeType.TITLECASE_LETTER:
+          case UnicodeType.UPPERCASE_LETTER:
           default:
             ch = ch.tolower ();
             ch.fully_decompose (false, retval);
index ec96eff..dbf2364 100644 (file)
@@ -52,6 +52,8 @@ public class MatchNameTests : Folks.TestCase
           this.test_match_name_4);
       this.add_test ("test potential match by name #5 ",
           this.test_match_name_5);
+      this.add_test ("test potential match by name #6 ",
+          this.test_match_name_6);
     }
 
   public override void set_up ()
@@ -119,6 +121,13 @@ public class MatchNameTests : Folks.TestCase
       assert (this._match >= Folks.MatchResult.HIGH);
     }
 
+  public void test_match_name_6 ()
+    {
+      /* Another one from bgo#678474, testing random punctuation in names */
+      this._test_match_name ("Alice Badger", "alice.badger");
+      assert (this._match >= Folks.MatchResult.HIGH);
+    }
+
   private async void _test_match_name_async ()
     {
       var store = BackendStore.dup ();