fix: path comparison considers core params

This commit is contained in:
Carlos Valente
2026-02-21 21:06:04 +01:00
committed by Carlos Valente
parent df588b8845
commit d9a18b0c42
2 changed files with 17 additions and 6 deletions
@@ -166,6 +166,14 @@ describe('arePathsEquivalent()', () => {
expect(arePathsEquivalent('preset/minimal', 'preset/minimal?test=b')).toBeTruthy();
});
it('distinguishes preset paths with different lock or token params', () => {
expect(arePathsEquivalent('preset/minimal', 'preset/minimal?n=1')).toBeFalsy();
expect(arePathsEquivalent('preset/minimal?n=1', 'preset/minimal?n=1')).toBeTruthy();
expect(arePathsEquivalent('preset/minimal', 'preset/minimal?token=abc')).toBeFalsy();
expect(arePathsEquivalent('preset/minimal?n=1&token=abc', 'preset/minimal?n=1')).toBeFalsy();
expect(arePathsEquivalent('preset/minimal?n=1&token=abc', 'preset/minimal?n=1&token=abc')).toBeTruthy();
});
it('considers edge cases for the url sharing feature', () => {
expect(arePathsEquivalent('timer?test=a&n=1=token=123', 'timer?test=b')).toBeFalsy();
expect(arePathsEquivalent('timer?test=a&n=1=token=123', 'timer?test=a')).toBeTruthy();
+9 -6
View File
@@ -151,16 +151,19 @@ export function arePathsEquivalent(currentPath: string, newPath: string): boolea
const currentUrl = new URL(currentPath, document.location.origin);
const newUrl = new URL(newPath, document.location.origin);
// For preset paths, only compare the path
if (currentUrl.pathname.startsWith('/preset/') || newUrl.pathname.startsWith('/preset/')) {
return currentUrl.pathname === newUrl.pathname;
}
// For regular paths, compare path and search params (ignoring token)
if (currentUrl.pathname !== newUrl.pathname) {
return false;
}
// For preset paths, only n and token are meaningful — ignore everything else
if (currentUrl.pathname.startsWith('/preset/')) {
return (
currentUrl.searchParams.get('n') === newUrl.searchParams.get('n') &&
currentUrl.searchParams.get('token') === newUrl.searchParams.get('token')
);
}
// For regular paths, compare all search params except n and token
currentUrl.searchParams.delete('token');
currentUrl.searchParams.delete('n');
newUrl.searchParams.delete('token');