Skip to content

Commit 40d1594

Browse files
committed
Update removeLocalhostFromBaseUrl to ensure the full path is stored
1 parent c773130 commit 40d1594

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packages/shared/src/utils/filePaths.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ describe('truncateFileName', () => {
225225
expect(result).toBe('/some/path/');
226226
});
227227

228+
it('should remove localhost from href but keeps the query and hash', () => {
229+
const href = 'http://localhost:3000/some/path/?query=value#fragment';
230+
const result = removeLocalhostFromBaseUrl(href);
231+
expect(result).toBe('/some/path/?query=value#fragment');
232+
});
233+
228234
it('should remove localhost from href', () => {
229235
const href = 'http://localhost:3000/';
230236
const result = removeLocalhostFromBaseUrl(href);
@@ -236,6 +242,7 @@ describe('truncateFileName', () => {
236242
const result = removeLocalhostFromBaseUrl(href);
237243
expect(result).toBe('/some/path/');
238244
});
245+
239246
it('should return the exact href if locahost is not the host name', () => {
240247
const href = 'https://www.example.com/';
241248
const result = removeLocalhostFromBaseUrl(href);

packages/shared/src/utils/filePaths.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export const removeLocalhostFromBaseUrl = (href: string) => {
104104
try {
105105
baseUrl = new URL(href);
106106
if (baseUrl.hostname === 'localhost') {
107-
return baseUrl.pathname;
107+
return baseUrl.pathname + baseUrl.search + baseUrl.hash;
108108
}
109109
return href;
110110
} catch (error) {

0 commit comments

Comments
 (0)