[evolution-data-server] Bug 735659 - EBookSqlite should ignore leading zeros when looking for phone number
- From: Mateusz Polrola <mpolrola src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Bug 735659 - EBookSqlite should ignore leading zeros when looking for phone number
- Date: Mon, 8 Sep 2014 13:56:35 +0000 (UTC)
commit 8231f9484281cc424a735799619881bfbc60cd5d
Author: Mateusz Polrola <mateusz polrola gmail com>
Date: Fri Aug 29 11:42:09 2014 +0200
Bug 735659 - EBookSqlite should ignore leading zeros when looking for phone number
EBookSqlite parses phonenumbers using libphonenumber - result of this
operation depends on currently set locale.
Some countries use leading 0 as area code prefix required when number is
presented in national format (without country code) e.g. in United
Kingdom.
This leading zeros may lead to wrong search queries if locale is not set
correctly and number in address book is stored in international format
and search query tries to find it using national format.
For example UK's phone number +44 2033445566 will be stored in user
address book in form - national number: 2033445566, country code: 44.
If user wants to query this number using national format -
02033445566 (with leading zero, e.g. number in such format could be
retrieved from users phone call log) result of operation depends on
currently set locale.
If system locale will be set to en_GB this number will be parsed using
en_GB as default region before making query which will lead to parsing it
into national number 2033445566 and country code 44 (the same like in database).
As EBookSqlite before making query is removing country code from numbers
for which default region was used, search query will look like:
... WHERE (phone_list.value_phone = '2033445566')
which will correctly find contact.
On the other hand the same search query won't return expected result
when system locale will be set to other locale than en_GB, e.g. en_US,
in that case 02033445566 number will be parsed into national number
02033445566 and country code 1, leading to a query
... WHERE (phone_list.value_phone = '02033445566')
Leading zero(s) won't allow to correctly find contact from address book.
EBookSqlite should remove them before making query, but leading
zeros shouldn't be removed from E164 values in contacts vCards.
This change adds additional parameter to
e_phone_number_get_national_number that indicates if leading
zeros should be removed from national number.
EBookSqlite code is updated to use national number without leading zeros
when creating search index.
.../libebook-contacts/e-phone-number-private.cpp | 15 ++++++++++++---
.../libebook-contacts/e-phone-number-private.h | 3 ++-
addressbook/libebook-contacts/e-phone-number.c | 6 ++++--
addressbook/libebook-contacts/e-phone-number.h | 3 ++-
.../libedata-book/e-book-backend-sqlitedb.c | 2 +-
addressbook/libedata-book/e-book-sqlite.c | 10 ++++++----
tests/libebook-contacts/test-phone-number.c | 4 ++--
7 files changed, 29 insertions(+), 14 deletions(-)
---
diff --git a/addressbook/libebook-contacts/e-phone-number-private.cpp
b/addressbook/libebook-contacts/e-phone-number-private.cpp
index b539bc4..01e3e60 100644
--- a/addressbook/libebook-contacts/e-phone-number-private.cpp
+++ b/addressbook/libebook-contacts/e-phone-number-private.cpp
@@ -29,6 +29,7 @@
/* C++ standard library */
#include <string>
+#include <sstream>
/* system headers */
#include <langinfo.h>
@@ -249,14 +250,22 @@ _e_phone_number_cxx_get_country_code (const EPhoneNumber *phone_number,
}
gchar *
-_e_phone_number_cxx_get_national_number (const EPhoneNumber *phone_number)
+_e_phone_number_cxx_get_national_number (const EPhoneNumber *phone_number,
+ gboolean with_leading_zeros)
{
g_return_val_if_fail (NULL != phone_number, NULL);
std::string national_number;
- e_phone_number_util_get_instance ()->GetNationalSignificantNumber (
- phone_number->priv, &national_number);
+ if (with_leading_zeros) {
+ e_phone_number_util_get_instance ()->GetNationalSignificantNumber (
+ phone_number->priv, &national_number);
+ } else {
+ std::ostringstream oss;
+ oss << phone_number->priv.national_number();
+ national_number = oss.str();
+ }
+
if (!national_number.empty ())
return g_strdup (national_number.c_str ());
diff --git a/addressbook/libebook-contacts/e-phone-number-private.h
b/addressbook/libebook-contacts/e-phone-number-private.h
index 537c4c5..35ef201 100644
--- a/addressbook/libebook-contacts/e-phone-number-private.h
+++ b/addressbook/libebook-contacts/e-phone-number-private.h
@@ -61,7 +61,8 @@ E_PHONE_NUMBER_LOCAL gchar * _e_phone_number_cxx_to_string (const
EPhoneNumber
EPhoneNumberFormat format);
E_PHONE_NUMBER_LOCAL gint _e_phone_number_cxx_get_country_code (const EPhoneNumber
*phone_number,
EPhoneNumberCountrySource
*source);
-E_PHONE_NUMBER_LOCAL gchar * _e_phone_number_cxx_get_national_number (const EPhoneNumber
*phone_number);
+E_PHONE_NUMBER_LOCAL gchar * _e_phone_number_cxx_get_national_number (const EPhoneNumber
*phone_number,
+ gboolean with_leading_zeros);
E_PHONE_NUMBER_LOCAL EPhoneNumberMatch _e_phone_number_cxx_compare (const EPhoneNumber
*first_number,
const EPhoneNumber
*second_number);
diff --git a/addressbook/libebook-contacts/e-phone-number.c b/addressbook/libebook-contacts/e-phone-number.c
index 60f1741..44ff715 100644
--- a/addressbook/libebook-contacts/e-phone-number.c
+++ b/addressbook/libebook-contacts/e-phone-number.c
@@ -271,11 +271,13 @@ e_phone_number_get_country_code (const EPhoneNumber *phone_number,
* Since: 3.8
**/
gchar *
-e_phone_number_get_national_number (const EPhoneNumber *phone_number)
+e_phone_number_get_national_number (const EPhoneNumber *phone_number,
+ gboolean with_leading_zeros)
{
#ifdef ENABLE_PHONENUMBER
- return _e_phone_number_cxx_get_national_number (phone_number);
+ return _e_phone_number_cxx_get_national_number (phone_number,
+ with_leading_zeros);
#else /* ENABLE_PHONENUMBER */
diff --git a/addressbook/libebook-contacts/e-phone-number.h b/addressbook/libebook-contacts/e-phone-number.h
index 376e95c..c070766 100644
--- a/addressbook/libebook-contacts/e-phone-number.h
+++ b/addressbook/libebook-contacts/e-phone-number.h
@@ -220,7 +220,8 @@ gchar * e_phone_number_to_string (const EPhoneNumber
*phone_number,
gint e_phone_number_get_country_code (const EPhoneNumber *phone_number,
EPhoneNumberCountrySource *source);
gchar * e_phone_number_get_national_number
- (const EPhoneNumber *phone_number);
+ (const EPhoneNumber *phone_number,
+ gboolean with_leading_zeros);
EPhoneNumberMatch e_phone_number_compare (const EPhoneNumber *first_number,
const EPhoneNumber *second_number);
diff --git a/addressbook/libedata-book/e-book-backend-sqlitedb.c
b/addressbook/libedata-book/e-book-backend-sqlitedb.c
index 725cb81..3ab1c9a 100644
--- a/addressbook/libedata-book/e-book-backend-sqlitedb.c
+++ b/addressbook/libedata-book/e-book-backend-sqlitedb.c
@@ -2038,7 +2038,7 @@ convert_phone (const gchar *normal,
if (number) {
EPhoneNumberCountrySource source;
- national_number = e_phone_number_get_national_number (number);
+ national_number = e_phone_number_get_national_number (number, TRUE);
country_code = e_phone_number_get_country_code (number, &source);
e_phone_number_free (number);
diff --git a/addressbook/libedata-book/e-book-sqlite.c b/addressbook/libedata-book/e-book-sqlite.c
index b649155..61801c8 100644
--- a/addressbook/libedata-book/e-book-sqlite.c
+++ b/addressbook/libedata-book/e-book-sqlite.c
@@ -3000,6 +3000,7 @@ ebsql_new_internal (const gchar *path,
static gchar *
convert_phone (const gchar *normal,
const gchar *region_code,
+ gboolean with_leading_zeros,
gint *out_country_code)
{
EPhoneNumber *number = NULL;
@@ -3016,7 +3017,7 @@ convert_phone (const gchar *normal,
if (number) {
EPhoneNumberCountrySource source;
- national_number = e_phone_number_get_national_number (number);
+ national_number = e_phone_number_get_national_number (number, with_leading_zeros);
country_code = e_phone_number_get_country_code (number, &source);
e_phone_number_free (number);
@@ -3178,6 +3179,7 @@ update_e164_attribute_params (EBookSqlite *ebsql,
number.national = convert_phone (
original_number,
ebsql->priv->region_code,
+ TRUE,
&(number.country_code));
}
@@ -3351,7 +3353,7 @@ ebsql_run_multi_insert_one (EBookSqlite *ebsql,
str = convert_phone (
normal, ebsql->priv->region_code,
- &country_code);
+ FALSE, &country_code);
/* :value_phone */
ret = sqlite3_bind_text (stmt, param_idx++, str, -1, g_free);
@@ -3640,7 +3642,7 @@ ebsql_run_insert (EBookSqlite *ebsql,
str = convert_phone (
normal, ebsql->priv->region_code,
- &country_code);
+ FALSE, &country_code);
ret = sqlite3_bind_text (stmt, param_idx++, str, -1, g_free);
if (ret == SQLITE_OK)
@@ -4676,7 +4678,7 @@ query_preflight_check (PreflightContext *context,
/* Collect values we'll need later while generating field
* tests, no need to parse the phone number more than once
*/
- phone_test->national = e_phone_number_get_national_number (number);
+ phone_test->national = e_phone_number_get_national_number (number,
FALSE);
phone_test->country = e_phone_number_get_country_code (number,
&source);
if (source == E_PHONE_NUMBER_COUNTRY_FROM_DEFAULT)
diff --git a/tests/libebook-contacts/test-phone-number.c b/tests/libebook-contacts/test-phone-number.c
index fb4dcbc..4822fb3 100644
--- a/tests/libebook-contacts/test-phone-number.c
+++ b/tests/libebook-contacts/test-phone-number.c
@@ -200,7 +200,7 @@ test_parse_and_format (gconstpointer data)
test_data->country_code);
g_assert_cmpuint (source, ==, test_data->country_source);
- national = e_phone_number_get_national_number (parsed);
+ national = e_phone_number_get_national_number (parsed, TRUE);
g_assert_cmpstr (national, ==, test_data->national_number);
g_free (national);
@@ -272,7 +272,7 @@ test_parse_auto_region (void)
g_assert_cmpint (e_phone_number_get_country_code (parsed, &source), ==, 1);
g_assert_cmpuint (source, ==, E_PHONE_NUMBER_COUNTRY_FROM_DEFAULT);
- national = e_phone_number_get_national_number (parsed);
+ national = e_phone_number_get_national_number (parsed, TRUE);
g_assert_cmpstr (national, ==, "2125423789");
g_free (national);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]