From d9a18b0c425114ead15e82ebc6a1d60f75285ce8 Mon Sep 17 00:00:00 2001 From: Carlos Valente Date: Sat, 21 Feb 2026 21:06:04 +0100 Subject: [PATCH] fix: path comparison considers core params --- .../src/common/utils/__tests__/urlPresets.test.ts | 8 ++++++++ apps/client/src/common/utils/urlPresets.ts | 15 +++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/apps/client/src/common/utils/__tests__/urlPresets.test.ts b/apps/client/src/common/utils/__tests__/urlPresets.test.ts index d00bc9f36..b11db2623 100644 --- a/apps/client/src/common/utils/__tests__/urlPresets.test.ts +++ b/apps/client/src/common/utils/__tests__/urlPresets.test.ts @@ -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(); diff --git a/apps/client/src/common/utils/urlPresets.ts b/apps/client/src/common/utils/urlPresets.ts index 4f4207e5f..8f4089497 100644 --- a/apps/client/src/common/utils/urlPresets.ts +++ b/apps/client/src/common/utils/urlPresets.ts @@ -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');