Repository navigation
fix: Add postcode validation for Latvia - #67460
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThe change adds Latvia postcode validation to ChangesLatvia postcode validation
Estimated code review effort: 1 (Trivial) | ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@plugins/woocommerce/changelog/67459-lv-postcode-validation`:
- Around line 1-4: Update the changelog entry wording to state that Latvia
previously accepted invalid values, rather than claiming it accepted any value;
preserve the existing significance and type metadata.
In `@plugins/woocommerce/includes/class-wc-validation.php`:
- Around line 146-148: Update the LV case in the postcode validation switch to
use a non-capturing optional LV- prefix and anchor the pattern with \z instead
of $, ensuring a trailing newline is rejected. Add a validation fixture covering
an LV postcode ending in a newline and assert it is invalid.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro Plus
Run ID: 59b514cb-3bdf-48cf-a6c1-da29325f697c
📒 Files selected for processing (3)
plugins/woocommerce/changelog/67459-lv-postcode-validationplugins/woocommerce/includes/class-wc-validation.phpplugins/woocommerce/tests/php/includes/class-wc-validation-test.php
|
@Saggre thank you for your contribution. There are some comments from CodeRabbit that need your attention. Could you take a look? After that please assign the PR to |
|
@ralucaStan I don't have permission to assign to |
Testing GuidelinesHi , Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed. Reminder: PR reviewers are required to document testing performed. This includes:
|
WC_Validation::is_postcode() does not normalise its input, so a Latvian postcode can reach it as "LV1050" or "LV 1050" rather than "LV-1050". The rule added in #67460 required the literal hyphen, so it rejected both. Before that PR they fell through to the fail-open default and were accepted. POST /wc/store/v1/checkout reaches this on a normal request. AbstractAddressSchema::sanitize_callback() formats the postcode with the raw country value but validates against the uppercased one, so a client sending country "lv" skips the LV case in wc_format_postcode() (which would reinsert the hyphen) and then hits the LV case in is_postcode(). Verified against a local store: rejected on trunk, accepted here. The separator is a literal space rather than \s, so a newline or tab between the prefix and the digits is still rejected. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix: accept Latvian postcodes without the LV prefix hyphen WC_Validation::is_postcode() does not normalise its input, so a Latvian postcode can reach it as "LV1050" or "LV 1050" rather than "LV-1050". The rule added in #67460 required the literal hyphen, so it rejected both. Before that PR they fell through to the fail-open default and were accepted. POST /wc/store/v1/checkout reaches this on a normal request. AbstractAddressSchema::sanitize_callback() formats the postcode with the raw country value but validates against the uppercased one, so a client sending country "lv" skips the LV case in wc_format_postcode() (which would reinsert the hyphen) and then hits the LV case in is_postcode(). Verified against a local store: rejected on trunk, accepted here. The separator is a literal space rather than \s, so a newline or tab between the prefix and the digits is still rejected. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * docs: document the LV postcode pattern and cover its edges Explain the optional prefix, the single hyphen or space separator, and why the pattern uses a literal space and \z rather than \s and $. Add rows for repeated and invalid separators, the top of the four digit range, and trailing characters. No behaviour change; every one of these already validated this way. Raised by CodeRabbit on #67684. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Submission Review Guidelines:
Changes proposed in this Pull Request:
Add support for LV postcode validation
Add LV cases to
WC_Validation_TestLV currently falls through to
default: $valid = true, so anything passes. I added formatting support for LV in #45478 but never the validation half, sowc_format_postcode( '1050', 'LV' )returnsLV-1050whileis_postcode( 'anything', 'LV' )returns true.The pattern is 4 digits with an optional
LV-prefix, prefix handling like the existing DK case, case insensitive like ES and NL.Documentation on the format:
https://www.upu.int/UPU/media/upu/PostalEntitiesFiles/addressingUnit/lvaEn.pdf
https://en.wikipedia.org/wiki/Postal_codes_in_Latvia
LV-NNNNCloses #67459.
How to test the changes in this Pull Request:
Covered by new data provider cases. Run with:
Manual:
ZZZZ: accepted on trunk, rejected on this branch.LV-1050,lv-1050and1050still pass.Testing that has already taken place:
Test runs above on wp-env, only WooCommerce active. PHPCS and PHPStan report nothing new on the changed files.
Milestone
Changelog entry
Changelog entry is committed in the branch at
plugins/woocommerce/changelog/67459-lv-postcode-validation(patch / fix).