Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions data/regions/PA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/worldwide/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Worldwide
VERSION = "2.0.1"
VERSION = "2.1.0"
end
2 changes: 1 addition & 1 deletion lib/worldwide/zip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down Expand Up @@ -515,7 +516,6 @@ def gb_style_outcode(country_code:, input:)
"NP",
"NZ",
"OM",
"PA",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: By removing PA from this set do we lose some shared normalizing capabilities?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for the legacy 4-digit codes only; the 10-character codes never validated on main, so they lose nothing.

  1. Lookalike autocorrection (OILZSB → 011258): O815 used to normalize to 0815; now it's rejected and the buyer sees the validation error. Keeping it would need a length-based PA special case, and that misfires on partially typed new codes (B2S5 → 8255, a valid 4-digit code). The legacy codes are PO-box zones that rarely appear in shipping addresses, and the field is optional, so I'd rather surface the error than silently rewrite the input.
  2. strip_extraneous_characters: true removed every non-digit (0815 PANAMA → 0815). That can't apply once letters are valid in PA codes.

Spaces and punctuation are still removed as before (0815, 0815. → 0815).

"PF",
"PG",
"PH",
Expand Down
54 changes: 54 additions & 0 deletions test/worldwide/regions/pa_test.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions test/worldwide/zip_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading