From e1da1db6af2930e9ed5045d3abb0c73c4f74d26e Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Sun, 16 Jun 2013 20:23:17 +0100 Subject: [PATCH] =?utf8?q?core:=20Keep=20leading=20=E2=80=98+=E2=80=99s=20?= =?utf8?q?when=20normalising=20phone=20numbers?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit These are needed to indicate country codes for international numbers. See: https://bugzilla.gnome.org/show_bug.cgi?id=685992 Closes: https://bugzilla.gnome.org/show_bug.cgi?id=701850 --- NEWS | 2 ++ folks/phone-details.vala | 5 +-- tests/folks/Makefile.am | 5 +++ tests/folks/phone-field-details.vala | 66 ++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 tests/folks/phone-field-details.vala diff --git a/NEWS b/NEWS index 5857778..507bd46 100644 --- a/NEWS +++ b/NEWS @@ -20,6 +20,8 @@ Bugs fixed: • Bug 704922 — key-file: do not use deprecated loop_run_with_non_fatal_timeout() • Bug 705196 — Linking a favorite TP contact with a EDS one unfavorite it • Bug 703516 — Build failing with EDS backend +• Bug 701850 — folks-DEBUG: phone-details.vala:160: + [PhoneDetails.get_normalised] unknown digit: + API changes: • Add PresenceDetails.client_types diff --git a/folks/phone-details.vala b/folks/phone-details.vala index fcdd0d9..f906990 100644 --- a/folks/phone-details.vala +++ b/folks/phone-details.vala @@ -1,6 +1,6 @@ /* * Copyright (C) 2011 Collabora Ltd. - * Copyright (C) 2011 Philip Withnall + * Copyright (C) 2011, 2013 Philip Withnall * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -146,7 +146,8 @@ public class Folks.PhoneFieldDetails : AbstractFieldDetails var digit = this.value.slice (i, i + 1); if (digit in PhoneFieldDetails._extension_chars || - digit in PhoneFieldDetails._valid_digits) + digit in PhoneFieldDetails._valid_digits || + (i == 0 && digit == "+")) { /* lets keep valid digits */ normalised_number += digit; diff --git a/tests/folks/Makefile.am b/tests/folks/Makefile.am index 336483d..95f0493 100644 --- a/tests/folks/Makefile.am +++ b/tests/folks/Makefile.am @@ -66,6 +66,7 @@ noinst_PROGRAMS = \ aggregation \ avatar-cache \ object-cache \ + phone-field-details \ init \ $(NULL) @@ -103,6 +104,10 @@ object_cache_SOURCES = \ object-cache.vala \ $(NULL) +phone_field_details_SOURCES = \ + phone-field-details.vala \ + $(NULL) + init_SOURCES = \ init.vala \ $(NULL) diff --git a/tests/folks/phone-field-details.vala b/tests/folks/phone-field-details.vala new file mode 100644 index 0000000..896a303 --- /dev/null +++ b/tests/folks/phone-field-details.vala @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2013 Philip Withnall + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + * + * Authors: Philip Withnall + */ + +using Gee; +using Folks; + +public class PhoneFieldDetailsTests : Folks.TestCase +{ + public PhoneFieldDetailsTests () + { + base ("PhoneFieldDetails"); + + this.add_test ("normalisation", this.test_normalisation); + } + + private struct NormalisationPair + { + string unnormalised; + string normalised; + } + + public void test_normalisation () + { + /* Array of pairs of strings, mapping unnormalised phone numbers to their + * expected normalised form. */ + const NormalisationPair[] normalisation_pairs = { + { "1-800-123-4567", "18001234567" }, + { "+1-800-123-4567", "+18001234567" }, + { "+1-800-123-4567P123", "+18001234567P123" }, + }; + + foreach (var s in normalisation_pairs) + { + var pfd1 = new PhoneFieldDetails (s.unnormalised); + assert (pfd1.get_normalised () == s.normalised); + } + } +} + +public int main (string[] args) +{ + Test.init (ref args); + + var tests = new PhoneFieldDetailsTests (); + tests.register (); + Test.run (); + tests.final_tear_down (); + + return 0; +} -- 2.7.4