diff --git a/CHANGELOG.md b/CHANGELOG.md index ae54cd66e..c5ba9eaa1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +--- + +## [2.1.0] - 2026-11-10 + +- Accept Panama's 10-character postal codes (`XXXXX-XXXXX`, for example `ADC96-M8H44`), as well as the 4-digit codes. `Zip.normalize` puts the hyphen after the 5th character. [#678](https://github.com/Shopify/worldwide/pull/678) - Add street-first `address1` formats for AR, AT, BE, BR, CH, CL, CZ, ES, FI, HU, MX, NO, PT, SE, and UY. --- diff --git a/Gemfile.lock b/Gemfile.lock index e5e266266..fc69206bf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -13,7 +13,7 @@ GIT PATH remote: . specs: - worldwide (2.0.1) + worldwide (2.1.0) activesupport (>= 7.0) i18n (>= 1.15) phonelib (~> 0.8) diff --git a/data/regions/PA.yml b/data/regions/PA.yml index 2f98ca877..026ab6f32 100644 --- a/data/regions/PA.yml +++ b/data/regions/PA.yml @@ -7,8 +7,8 @@ unit_system: metric tax_name: ITBMS group: Central American Countries group_name: Central America -zip_regex: "^\\d{4}$" -zip_example: "0801" +zip_regex: "^(?:\\d{4}|[A-Z0-9]{2}[2-9A-HJ-NP-TV-XZ]{3}[ -]?[2-9A-HJ-NP-TV-XZ]{5})$" +zip_example: "ADC96-M8H44" zip_requirement: optional phone_number_prefix: 507 week_start_day: sunday @@ -45,7 +45,7 @@ example_address: address2: y entre calles 35 y, C. 36 Este, ⁠El Marañón city: Panamá province_code: PA-8 - zip: '0815' + zip: ADC96-M8H44 phone: "+507 524-8900" zones: - name: Bocas del Toro diff --git a/lib/worldwide/version.rb b/lib/worldwide/version.rb index af407408b..f579b5dd1 100644 --- a/lib/worldwide/version.rb +++ b/lib/worldwide/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Worldwide - VERSION = "2.0.1" + VERSION = "2.1.0" end diff --git a/lib/worldwide/zip.rb b/lib/worldwide/zip.rb index bd8955d03..6ea3ec8e0 100644 --- a/lib/worldwide/zip.rb +++ b/lib/worldwide/zip.rb @@ -396,6 +396,7 @@ def gb_style_outcode(country_code:, input:) MT: [[7, " ", 3], [5, " ", 3]], NL: [[6, " ", 4]], + PA: [[10, "-", 5]], PL: [[5, "-", 2]], PN: [[7, " ", 4]], PT: [[7, "-", 4]], @@ -515,7 +516,6 @@ def gb_style_outcode(country_code:, input:) "NP", "NZ", "OM", - "PA", "PF", "PG", "PH", diff --git a/test/worldwide/regions/pa_test.rb b/test/worldwide/regions/pa_test.rb new file mode 100644 index 000000000..826d51c62 --- /dev/null +++ b/test/worldwide/regions/pa_test.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require "test_helper" + +module Worldwide + class PaTest < ActiveSupport::TestCase + setup do + @region = Worldwide.region(code: "PA") + end + + test "four digit postal codes are valid" do + assert @region.valid_zip?("0815") # Correos y Telégrafos, Avenida Central y Calle 34 + end + + test "ten character postal codes are valid" do + assert @region.valid_zip?("ADC96-M8H44") # Municipio de Panamá, Avenida Justo Arosemena + end + + test "ten character postal codes are valid without the hyphen, in lowercase, or with spaces" do + ["ADC96M8H44", "adc96-m8h44", "ADC96 M8H44", "ADC96M-8H44", "ADC96\u2013M8H44"].each do |zip| + assert @region.valid_zip?(zip), "Expected #{zip.inspect} to be valid" + end + end + + test "zip_regex accepts a hyphen, a space, or nothing between the two groups" do + regex = Regexp.new(@region.zip_regex) + + ["ADC96-M8H44", "ADC96 M8H44", "ADC96M8H44"].each do |zip| + assert_match regex, zip + end + ["ADC96--M8H44", "ADC96 M8H44", "ADC96_M8H44"].each do |zip| + assert_no_match regex, zip + end + end + + test "blank postal codes are valid because the postal code is optional" do + assert @region.valid_zip?(nil) + assert @region.valid_zip?("") + end + + test "ten character postal codes with characters outside the official alphabet are invalid" do + # After the 2-character prefix, codes use only 23456789ABCDEFGHJKLMNPQRSTVWXZ + ["AD096-M8H44", "ADC16-M8H44", "ADC96-I8H44", "ADC96-M8O44", "ADC96-M8H4U", "ADC96-Y8H44"].each do |zip| + assert_not @region.valid_zip?(zip), "Expected #{zip.inspect} to be invalid" + end + end + + test "codes of other lengths are invalid" do + ["815", "08150", "C96M8H44", "ADC96-M8H4", "ADC96-M8H442"].each do |zip| + assert_not @region.valid_zip?(zip), "Expected #{zip.inspect} to be invalid" + end + end + end +end diff --git a/test/worldwide/zip_test.rb b/test/worldwide/zip_test.rb index 3d5274ba4..87249aeb0 100644 --- a/test/worldwide/zip_test.rb +++ b/test/worldwide/zip_test.rb @@ -16,6 +16,10 @@ class PostalCodeTest < ActiveSupport::TestCase false, Zip.numeric_only_zip?(country_code: "CA"), ) + assert_equal( + false, + Zip.numeric_only_zip?(country_code: "PA"), + ) end test "pure_numeric_only_zip? returns true if country has numeric only zip code without any special chars" do @@ -760,6 +764,12 @@ class PostalCodeTest < ActiveSupport::TestCase [:MT, "PTA 1226", "PTA1226"], # Modern format (since 2007): 3 letters and 4 digits [:NL, "1071 LN", "1071LN"], # Concertgebouw, Amsterdam [:NL, "1071 LN", "1071 LN"], # Concertgebouw, Amsterdam + [:PA, "0815", "0815"], # Four-digit code, Correos y Telégrafos, Avenida Central y Calle 34 + [:PA, "ADC96-M8H44", "ADC96M8H44"], # Ten-character code, Municipio de Panamá + [:PA, "ADC96-M8H44", "adc96 m8h44"], # Ten-character code, lowercase with a space + [:PA, "ADC96-M8H44", "ADC96M-8H44"], # Ten-character code, hyphen in the wrong place + [:PA, "ADC96-M8H44", "ADC96\u2013M8H44"], # Ten-character code, en dash + [:PA, "ACC9B-EJS3W", "ACC9BEJS3W"], # Biomuseo, Amador: letters are not changed into digits [:PL, "81-451", "81451"], # Experyment Science Centre, Gdynia [:PN, "PCRN 1ZZ", "PCRN1ZZ"], [:PT, "4050-253", "4050253"], # Bolsa Palace, Porto