Skip to content

Commit 7229151

Browse files
committed
add decoding for url-encoded paths
1 parent 87eb365 commit 7229151

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

.changeset/plenty-schools-end.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/hydrogen': patch
3+
---
4+
5+
Fixed bug where file paths containing spaces were causing errors with virtual routes by decoding URL-encoded paths

packages/hydrogen/src/vite/get-virtual-routes.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,16 @@ describe('virtual routes', () => {
2929
]),
3030
});
3131
});
32+
33+
it('handles file paths with spaces correctly', async () => {
34+
const result = await getVirtualRoutesV3();
35+
36+
result.routes.forEach((route) => {
37+
expect(route.file).not.toContain('%20');
38+
expect(route.file).not.toContain('%');
39+
});
40+
41+
expect(result.layout.file).not.toContain('%20');
42+
expect(result.layout.file).not.toContain('%');
43+
});
3244
});

packages/hydrogen/src/vite/get-virtual-routes.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ function getVirtualRoutesPath(
1717
}, basePath);
1818

1919
// Getting rid of the drive path (ie. '/C:/') in windows
20-
return new URL(forFile, virtualRoutesPath).pathname.replace(
20+
const pathname = new URL(forFile, virtualRoutesPath).pathname.replace(
2121
/^\/[a-zA-Z]:\//,
2222
'/',
2323
);
24+
25+
// Decode URI components to handle spaces and special characters in file paths
26+
return decodeURIComponent(pathname);
2427
}
2528

2629
export async function getVirtualRoutesV3() {

0 commit comments

Comments
 (0)