Skip to content

Commit

Permalink
Apply lower() and strip() when matching values with map.
Browse files Browse the repository at this point in the history
  • Loading branch information
zedzior committed Apr 26, 2024
1 parent 652a9ad commit 1666460
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions saleor/account/i18n.py
Expand Up @@ -201,9 +201,10 @@ def substitute_invalid_values(data):
return
if custom_names := VALID_ADDRESS_EXTENSION_MAP.get(country_code):
for field_name, mapping in custom_names.items():
actual_value = data.get(field_name)
if actual_value in mapping:
data[field_name] = mapping[actual_value]
actual_value = data.get(field_name, "").strip().lower()
mapping_adjusted = {k.strip().lower(): v for k, v in mapping.items()}
if actual_value in mapping_adjusted:
data[field_name] = mapping_adjusted[actual_value]


def get_address_form_class(country_code):
Expand Down
4 changes: 4 additions & 0 deletions saleor/account/tests/test_account.py
Expand Up @@ -322,6 +322,10 @@ def test_customers_show_staff_with_order(admin_user, channel_USD):
("Dublin", "Co. Dublin", True),
("Co. Dublin", "Co. Dublin", True),
("Dummy Area", None, False),
("dublin", "Co. Dublin", True),
(" dublin ", "Co. Dublin", True),
("", "", True),
(None, "", True),
],
)
@patch.dict(
Expand Down

0 comments on commit 1666460

Please sign in to comment.