Skip to content

Commit

Permalink
Lowercase storefront redirects to make them case insensitive. (#1941)
Browse files Browse the repository at this point in the history
  • Loading branch information
blittle committed Apr 4, 2024
1 parent d1e5ca5 commit 14bb5df
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-impalas-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/hydrogen': patch
---

Change StorefrontRedirect to base case insensitive in querying redirect URLs from the Storefront API.
22 changes: 22 additions & 0 deletions packages/hydrogen/src/routing/redirect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,28 @@ describe('storefrontRedirect', () => {
});
});

it('queries the SFAPI with the url lower cased', async () => {
queryMock.mockResolvedValueOnce({
urlRedirects: {edges: [{node: {target: shopifyDomain + '/some-page'}}]},
});

await expect(
storefrontRedirect({
storefront: storefrontMock,
request: new Request('https://domain.com/some-PAGE'),
}),
).resolves.toEqual(
new Response(null, {
status: 301,
headers: {location: shopifyDomain + '/some-page'},
}),
);

expect(queryMock).toHaveBeenCalledWith(expect.anything(), {
variables: {query: 'path:/some-page'},
});
});

it('strips remix _data query parameter on soft navigations', async () => {
queryMock.mockResolvedValueOnce({
urlRedirects: {edges: [{node: {target: shopifyDomain + '/some-page'}}]},
Expand Down
6 changes: 3 additions & 3 deletions packages/hydrogen/src/routing/redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export async function storefrontRedirect(
searchParams.delete('return_to');
searchParams.delete('_data');

const redirectFrom = matchQueryParams
? url.toString().replace(url.origin, '')
: pathname;
const redirectFrom = (
matchQueryParams ? url.toString().replace(url.origin, '') : pathname
).toLowerCase();

if (url.pathname === '/admin' && !noAdminRedirect) {
return createRedirectResponse(
Expand Down

0 comments on commit 14bb5df

Please sign in to comment.