Skip to content

Commit

Permalink
fix: action redirect accidentally stripped searchparams (#5349)
Browse files Browse the repository at this point in the history
Fix #5342
  • Loading branch information
mhevery authored Oct 24, 2023
1 parent 7c0e91a commit 1f75648
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,20 @@ export function isLastModulePageRoute(routeModules: RouteModule[]) {
}

export function getPathname(url: URL, trailingSlash: boolean | undefined) {
url = new URL(url);
if (url.pathname.endsWith(QDATA_JSON)) {
return url.pathname.slice(0, -QDATA_JSON.length + (trailingSlash ? 1 : 0)) + url.search;
url.pathname = url.pathname.slice(0, -QDATA_JSON.length);
}
return url.pathname;
if (trailingSlash) {
if (!url.pathname.endsWith('/')) {
url.pathname += '/';
}
} else {
if (url.pathname.endsWith('/')) {
url.pathname = url.pathname.slice(0, -1);
}
}
return url.toString().substring(url.origin.length);
}

export const encoder = /*#__PURE__*/ new TextEncoder();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { describe, it, expect } from 'vitest';
import { getPathname } from './resolve-request-handlers';

describe('resolve-request-handler', () => {
describe('getPathname', () => {
it('should remove q-data.json', () => {
expect(getPathname(new URL('http://server/path/q-data.json?foo=bar#hash'), true)).toBe(
'/path/?foo=bar#hash'
);
expect(getPathname(new URL('http://server/path/q-data.json?foo=bar#hash'), false)).toBe(
'/path?foo=bar#hash'
);
});

it('should pass non q-data.json through', () => {
expect(getPathname(new URL('http://server/path?foo=bar#hash'), true)).toBe(
'/path/?foo=bar#hash'
);
expect(getPathname(new URL('http://server/path/?foo=bar#hash'), false)).toBe(
'/path?foo=bar#hash'
);
});
});
});

0 comments on commit 1f75648

Please sign in to comment.