Skip to content

Keep / # ( ) : in imported street addresses - #292

Closed
Marvin-Magmodules wants to merge 3 commits into
masterfrom
fix/street-sanitize-allowlist
Closed

Marvin-Magmodules wants to merge 3 commits into
masterfrom
fix/street-sanitize-allowlist

Conversation

@Marvin-Magmodules

Copy link
Copy Markdown
Member

PATTERN_STREET strips every character outside its allowlist, so an imported street like Examplestreet 55/3 was stored as Examplestreet 553. That is not just a missing character — the house number itself becomes a different, undeliverable one. In the separate-house-number path the ext / 3 collapsed to 3 the same way.

The allowlist was copied from Magento\Customer\Model\Validator\Street so addressRepository->save() would not reject imported addresses, but that validator rejects none of these characters: its character class closes early on the "[] sequence, and isValidStreet() returns true whenever the pattern fails to match. An E2E import confirms it — the order is created and the address is stored as Examplestreet / 55/3.

Allow the punctuation that legitimately appears in addresses: / for house-number separators (AT, PL, CZ, IT), # for unit numbers, ( ) for parenthetical additions, : for box numbers. Angle brackets and the rest stay stripped.

The second commit adds the tests: a PHPUnit suite on getStreet() (15 cases, 9 of them fail against the old pattern) plus one case in the order import E2E matrix. The module had no PHPUnit setup, so this brings over the arrangement from magento2-bol/magento2-eboekhouden — phpunit.xml.dist, a bootstrap, Test/composer.json, and a phpunit.yml workflow on 2.4.7/2.4.8-p4/2.4.9. Both are export-ignored, so nothing extra ships in the package.

Marvin-Magmodules and others added 3 commits September 14, 2026 10:16
PATTERN_STREET strips every character outside its allowlist, so a street
like "Examplestreet 55/3" was stored as "Examplestreet 553". That is not
only a missing character: the house number itself changes into a
different, undeliverable one. In the separate-house-number path the ext
"/ 3" collapsed to "3" the same way.

The allowlist was copied from Magento\Customer\Model\Validator\Street so
that addressRepository->save() would not reject imported addresses, but
that validator rejects none of these characters - its character class
closes early on the "[] sequence, and isValidStreet() returns true
whenever the pattern fails to match. Verified against the real
customer_address/save composite validator: / # + : * ? ! @ $ % ^ = ~ ; |
\ { } < > ( ) are all accepted.

Allow the punctuation that legitimately appears in addresses: / for
house-number separators (AT, PL, CZ, IT), # for unit numbers, ( ) for
parenthetical additions and : for box numbers. Angle brackets and the
rest stay stripped.
The street pattern decides what reaches the stored address, and the ways it
can go wrong are invisible in a diff: a dropped separator turns "55/3" into
"553", a different house. That belongs in tests that run on every change,
not in a reviewer's head.

The module had no PHPUnit setup at all, so this brings over the arrangement
already used in magento2-bol and magento2-eboekhouden: phpunit.xml.dist, a
bootstrap that resolves the surrounding Magento install, and test-only
dependencies in Test/composer.json - kept out of the module's own
composer.json so the shipped package stays dependency-free, and installed
separately because Magento's root autoloader excludes **/Test/** from its
classmap and breaks the PHPUnit copy shipped with Magento.

AddressHandlerTest covers getStreet() from both sides: the punctuation that
carries address meaning survives (/ # ( ) :) across separate-house-number
and combined-address-line paths and all three street_lines foldings, and
everything outside the allowlist is still stripped, so widening it cannot
quietly become an open door. Against the old pattern 9 of the 15 cases fail;
the 5 stripping cases pass either way, which is the point of keeping both.

What a unit test cannot settle is the reason the allowlist was narrow in the
first place: the assumption that addressRepository->save() would reject
these characters. Only a real import does, so the order import matrix gains
one case - order in with "55/3", order out with "Examplestreet 55/3" on both
addresses, and an explicit assertion that "553" is nowhere in it.
buildOrderData gains street, houseNumber and houseNumberExt overrides, and
OrderViewPage gains address getters that keep the line breaks so a street
split across the wrong lines shows up in the assertion diff.

/Test was already export-ignored; phpunit.xml.dist sits at the root and is
added to .gitattributes so it does not ship with the package either.
@Marvin-Magmodules
Marvin-Magmodules force-pushed the fix/street-sanitize-allowlist branch from 3155942 to 66a3d52 Compare September 22, 2026 08:42
@Marvin-Magmodules

Copy link
Copy Markdown
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants