From 1471bedc3fa454d1a660a54791aaa0c19bb462fd Mon Sep 17 00:00:00 2001 From: Ville Vesilehto Date: Sat, 10 Oct 2026 14:40:09 +0300 Subject: [PATCH] fix(cpp): use RFC3966 extension syntax in FormatByPattern FormatByPattern always appended the extension in national style, so RFC3966 output ended in " ext. 1234" instead of ";ext=1234". That is not a valid tel URI and differs from Format(), which already formats the extension for the requested number format, and from the Java and JavaScript formatByPattern. Pass the requested number format through. Signed-off-by: Ville Vesilehto --- cpp/src/phonenumbers/phonenumberutil.cc | 3 ++- cpp/test/phonenumbers/phonenumberutil_test.cc | 6 ++++++ pending_code_changes.txt | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cpp/src/phonenumbers/phonenumberutil.cc b/cpp/src/phonenumbers/phonenumberutil.cc index 705c934d92..cd7d231a61 100644 --- a/cpp/src/phonenumbers/phonenumberutil.cc +++ b/cpp/src/phonenumbers/phonenumberutil.cc @@ -1222,7 +1222,8 @@ void PhoneNumberUtil::FormatByPattern( FormatNsnUsingPattern(national_significant_number, num_format_copy, number_format, formatted_number); } - MaybeAppendFormattedExtension(number, *metadata, NATIONAL, formatted_number); + MaybeAppendFormattedExtension(number, *metadata, number_format, + formatted_number); PrefixNumberWithCountryCallingCode(country_calling_code, number_format, formatted_number); } diff --git a/cpp/test/phonenumbers/phonenumberutil_test.cc b/cpp/test/phonenumbers/phonenumberutil_test.cc index 97cf1f08a4..4ff7c217f1 100644 --- a/cpp/test/phonenumbers/phonenumberutil_test.cc +++ b/cpp/test/phonenumbers/phonenumberutil_test.cc @@ -1333,6 +1333,12 @@ TEST_F(PhoneNumberUtilTest, FormatByPattern) { number_formats, &formatted_number); EXPECT_EQ("tel:+1-650-253-0000", formatted_number); + PhoneNumber test_number_with_extension(test_number); + test_number_with_extension.set_extension("1234"); + phone_util_.FormatByPattern(test_number_with_extension, + PhoneNumberUtil::RFC3966, number_formats, + &formatted_number); + EXPECT_EQ("tel:+1-650-253-0000;ext=1234", formatted_number); // $NP is set to '1' for the US. Here we check that for other NANPA countries // the US rules are followed. diff --git a/pending_code_changes.txt b/pending_code_changes.txt index 8b13789179..57000973bf 100644 --- a/pending_code_changes.txt +++ b/pending_code_changes.txt @@ -1 +1,2 @@ - +Code changes: + - Fixed FormatByPattern in the C++ version to format the extension for the requested number format, so RFC3966 output uses ";ext=" as in the Java version. \ No newline at end of file