Skip to content

Match whole path segments in HardcodedRoutes - #1363

Open
RaphaelFakhri wants to merge 1 commit into
Shopify:mainfrom
RaphaelFakhri:fix/hardcoded-routes-prefix
Open

RaphaelFakhri wants to merge 1 commit into
Shopify:mainfrom
RaphaelFakhri:fix/hardcoded-routes-prefix

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

What are you adding in this PR?

Fixes #1362

HardcodedRoutes used startsWith to match a hardcoded path against the routes table, so a path that only shares a prefix with a route was reported. /cartography was reported as /cart, /searching as /search, and /collections/all-shoes was reported as /collections/all with a suggestion to use routes.all_products_collection_url, which links to a different page.

The check now matches a route only when it is followed by the end of the value, /, ? or #. This applies to both href/action attributes and the link_to filter. /cart/change?line=1, /collections/{{ collection.handle }} and /cart#drawer are still reported.

What's next? Any followup issues?

None.

What did you learn?

The routes table is iterated in reverse so longer routes such as /collections/all win over /collections. With the boundary check, a longer route that does not match on a segment boundary now falls back to the shorter one.

Tophatting

Added a spec case with /cartography, /searching, /accounting, /carts, /collections/all-shoes and /cart#drawer. Without the source change the case fails with 6 offenses instead of 2.

npx vitest run packages/theme-check-common/src/checks/hardcoded-routes
  • I added screenshots of the changes (before and after the changes if applicable)

Before you deploy

  • I included a patch bump changeset

@RaphaelFakhri
RaphaelFakhri requested a review from a team as a code owner October 21, 2026 07:35
@RaphaelFakhri

Copy link
Copy Markdown
Author

I have signed the CLA.

@RaphaelFakhri
RaphaelFakhri force-pushed the fix/hardcoded-routes-prefix branch from 7fe9813 to 46b0c2f Compare October 29, 2026 13:03
@RaphaelFakhri

Copy link
Copy Markdown
Author

Rebased onto main. Since 97eb55d replaced the check tests with executable specs, the test case moved from hardcoded-routes/index.spec.ts to a should only match whole path segments case in specs/checks/hardcoded-routes.yml. The case fails without the change, and the HardcodedRoutes specs pass with it.

This branch has not been deployed

No deployments
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.

HardcodedRoutes flags paths that only share a prefix with a route

1 participant