mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-01 12:29:10 +00:00
fix: path comparison considers core params
This commit is contained in:
committed by
Carlos Valente
parent
df588b8845
commit
d9a18b0c42
@@ -166,6 +166,14 @@ describe('arePathsEquivalent()', () => {
|
|||||||
expect(arePathsEquivalent('preset/minimal', 'preset/minimal?test=b')).toBeTruthy();
|
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', () => {
|
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=b')).toBeFalsy();
|
||||||
expect(arePathsEquivalent('timer?test=a&n=1=token=123', 'timer?test=a')).toBeTruthy();
|
expect(arePathsEquivalent('timer?test=a&n=1=token=123', 'timer?test=a')).toBeTruthy();
|
||||||
|
|||||||
@@ -151,16 +151,19 @@ export function arePathsEquivalent(currentPath: string, newPath: string): boolea
|
|||||||
const currentUrl = new URL(currentPath, document.location.origin);
|
const currentUrl = new URL(currentPath, document.location.origin);
|
||||||
const newUrl = new URL(newPath, 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) {
|
if (currentUrl.pathname !== newUrl.pathname) {
|
||||||
return false;
|
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('token');
|
||||||
currentUrl.searchParams.delete('n');
|
currentUrl.searchParams.delete('n');
|
||||||
newUrl.searchParams.delete('token');
|
newUrl.searchParams.delete('token');
|
||||||
|
|||||||
Reference in New Issue
Block a user