Repository navigation
Allow single inner spaces in tracking number lookup (regression from #352) - #413
Conversation
Tracking numbers are generated with the first three characters of the company name as their prefix, so a company named "Al Noor" issues numbers like "AL 7796486490AE". The lookup pattern added in fleetbase#352 has no space in its character class, so the public tracking page and fleet-ops/lookup now answer "not found" for those numbers. Allow a space only when it sits between two allowed characters. Leading, trailing and repeated spaces, tabs, newlines, quotes and other symbols are still refused, and the 100 character limit is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…refix generateTrackingNumber() takes the first three characters of the company name as they are, so names such as "Al Noor" or "A&B Logistics" produce numbers containing a space or "&", and names in non-Latin scripts produce partial multibyte characters. Keep only A-Z and 0-9 from those three characters and fall back to FLB when nothing is left. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #413 +/- ##
===========================================
Coverage 100.00% 100.00%
- Complexity 13596 13598 +2
===========================================
Files 634 634
Lines 49342 49344 +2
===========================================
+ Hits 49342 49344 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks @shivanathd, this looks good, and I'm keeping both commits.
Retargeted to |
|
Follow-up: the root cause, which is spaces getting into generated numbers at all, is fixed in #416, stacked on this PR. As well as the prefix, the region suffix could contain spaces ( |
Since #352 (merged 7 Oct 2026) the public tracking lookup and
fleet-ops/lookupreject any tracking number that contains a space. Some generated numbers do contain one, so those orders can no longer be tracked. Numbers like this resolved fine up to v0.7.68.Why the numbers contain a space
TrackingNumber::generateTrackingNumber()builds the prefix fromstrtoupper(substr($company->name, 0, 3)). A company named "Al Noor Transport" therefore issues numbers likeAL 7796486490AE.TrackingResolver::NUMBER_PATTERNandOrderController::normalizeTrackingLookup()both use/^[A-Za-z0-9][A-Za-z0-9._\-]{0,99}$/, which has no space, so these numbers now get the "not found" answer.Changes
Commit 1: accept single inner spaces in lookups. Both patterns become:
A space is allowed only when an allowed character follows it. Leading, trailing and double spaces are still refused, as are tabs, newlines, quotes,
&and everything else the old pattern refused. The 100-character limit is unchanged. Both call sites alreadytrim()first, so a number pasted with surrounding spaces still resolves, as before.Commit 2 (optional, drop it if you prefer): keep only
A-Z0-9in the generated prefix. New numbers no longer get a space,&or'from the company name (e.g. "A&B Logistics" currently givesA&B…, which no lookup accepts). The fallback isFLBwhen nothing is left, which also covers names in non-Latin scripts: todaysubstr(…, 0, 3)cuts those mid-character. The logic moves into a smallTrackingNumber::trackingNumberPrefix()helper so it can be unit tested. Numbers already issued keep working through commit 1.Tests
TrackingResolverTest: new case for inner spaces.AL 7796486490AEandABC1234567890AEresolve." AL1"and"AL1 "fail the pattern itself.AL 1,AL'1,AL&1, tab, newline and 101 characters are refused.OrderControllerContractsTest(fix(tracking): throttle the public order lookup and return a minimal resource #352's lookup test):AL 7796486490AEnow reaches the query;AL 1, tab, newline andAL&1still don't.TrackingNumberTest: prefix cases (NOR,AL,AB,3PL, Arabic name →FLB, blank/null →FLB).I ran these on PHP 8.2 with Pest:
TrackingResolverTest: 6/6 pass.TrackingNumberTest: 6/6 pass.QuerySeamsTest: 10/10 pass.ModelLookupFallbackSeamsTest: 4/4 pass.OrderControllerContractsTest: 23/24 pass. The one error isproof_photo_helpers_…, which needs the GD extension my container lacks; it errors the same way onmain.The new resolver and controller cases fail on
mainand pass with this change.php-cs-fixer --dry-runis clean on the changed lines.phpstanon the three changed source files reports the same findings asmain(none new).Related: #352, #181 (custom tracking numbers would face the same pattern).
This PR was prepared with an AI coding tool (Claude Code) and reviewed by Shiv. Found by Mindcat (mindcat.ai).
Generated by Claude Code