Skip to content

fix(tracking): generate tracking numbers from letters and digits only - #416

Merged
roncodes merged 3 commits into
release/v0.6.75from
fix/tracking-number-generation-alphanumeric
Oct 23, 2026
Merged

roncodes merged 3 commits into
release/v0.6.75from
fix/tracking-number-generation-alphanumeric

Conversation

@roncodes

Copy link
Copy Markdown
Member

Root-cause fix for the tracking numbers with spaces from #413. #413 makes lookups accept the numbers already issued. This PR stops new ones from containing anything but letters and digits.

Stacked on #413. This branch contains #413's two commits. Merge #413 into release/v0.6.75 first; after that, this PR's diff is only the last commit.

Why

TrackingNumber::generateTrackingNumber() builds a number from a company prefix, random digits and a region suffix. Both ends could still contain spaces or punctuation:

  • Prefix: Allow single inner spaces in tracking number lookup (regression from #352) #413's commit 2 takes the first three characters of the company name, then removes anything that isn't a letter or digit. So "Al Noor Transport" gives AL and "A&B Logistics" gives AB. That's safe, but shorter than intended.
  • Suffix: the region was appended as given (strtoupper($region)). The region falls back to the pickup's province or district when the pickup has no country (Payload::getPickupRegion(), ResolvesOrderServiceStops), and POST /v1/tracking-numbers accepts any string. So a pickup in "New York" issued numbers ending in NEW YORK.

Changes

  • trackingNumberPrefix() removes anything that isn't a letter or digit first, then takes three characters: ALN, ABL, OBR. It falls back to FLB, which is also what names in non-Latin scripts get.
  • New trackingNumberSuffix() keeps the region's letters and digits (NEWYORK) and falls back to SG.
  • Both use a shared trackingNumberCharacters() helper (ASCII A-Z0-9, upper-cased).

Numbers already issued are not renamed, because that would break printed labels and barcodes. They keep resolving through #413's lookup change.

Tests

  • TrackingNumberTest:
    • Prefix cases, including punctuation, accents, a short name, a non-Latin name, blank and null.
    • Suffix cases: a province name, padding, accents, a non-Latin region, blank and null.
    • Generated numbers match /^[A-Z0-9]+$/ for awkward regions.
  • These pass locally with PHP 8.4: TrackingNumberTest, ModelLookupFallbackSeamsTest, TrackingResolverTest, ObserverContractsTest, QuerySeamsTest and OrderControllerContractsTest (73 tests). php-cs-fixer is clean.

shivanathd and others added 3 commits October 23, 2026 01:50
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 #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>
Two parts of a generated number could carry a space or punctuation:

- The prefix took the first three characters of the company name, then
  dropped what was not a letter or digit, so "Al Noor Transport" gave AL and
  "A&B Logistics" gave AB. It now skips those characters first and takes the
  first three letters or digits (ALN, ABL), falling back to FLB.
- The suffix appended the region as given. The region falls back to the
  pickup's province or district when it has no country, and
  POST /v1/tracking-numbers accepts any string, so a pickup in "New York"
  issued ...NEW YORK. It now keeps only letters and digits, falling back to SG.

Numbers already issued keep working through the lookup change in this PR.
@codecov

codecov Bot commented Oct 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (33032e5) to head (fdaa94a).
⚠️ Report is 10 commits behind head on release/v0.6.75.

Additional details and impacted files
@@                 Coverage Diff                 @@
##             release/v0.6.75      #416   +/-   ##
===================================================
  Coverage             100.00%   100.00%           
- Complexity             13596     13601    +5     
===================================================
  Files                    634       634           
  Lines                  49342     49349    +7     
===================================================
+ Hits                   49342     49349    +7     
Flag Coverage Δ
backend 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@roncodes
roncodes merged commit a4cdc2d into release/v0.6.75 Oct 23, 2026
8 checks passed
@roncodes
roncodes deleted the fix/tracking-number-generation-alphanumeric branch October 23, 2026 04:21
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