From 966a984eb0217cc5d5c4bd7ddef3c281a7165d0f Mon Sep 17 00:00:00 2001 From: Jakob Scheid Date: Sun, 26 Jul 2026 23:06:38 +0200 Subject: [PATCH] feat(settings): filter characters that would cause a broken URL from settings page path --- .../composables/__tests__/useSettingsPage.test.js | 10 +++++++++- src/features/settings/composables/useSettingsPage.js | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/features/settings/composables/__tests__/useSettingsPage.test.js b/src/features/settings/composables/__tests__/useSettingsPage.test.js index 6723aa3..b300c0c 100644 --- a/src/features/settings/composables/__tests__/useSettingsPage.test.js +++ b/src/features/settings/composables/__tests__/useSettingsPage.test.js @@ -47,7 +47,15 @@ describe('useSettingsPage', () => { { path: 'a..b..', expected: ['a', 'b'] }, { path: '.a..b..', expected: ['a', 'b'] }, { path: '..a..b.', expected: ['a', 'b'] }, - { path: '..a.....b.c..d....', expected: ['a', 'b', 'c', 'd'] } + { path: '..a.....b.c..d....', expected: ['a', 'b', 'c', 'd'] }, + { path: 'a.b.c/', expected: ['a', 'b', 'c'] }, + { path: 'a.#b.c', expected: ['a', 'b', 'c'] }, + { path: 'a.#b.c/', expected: ['a', 'b', 'c'] }, + { path: 'a1.#b.c/', expected: ['a1', 'b', 'c'] }, + { path: 'a-1.#b.c/', expected: ['a-1', 'b', 'c'] }, + { path: 'a-1.b@.c', expected: ['a-1', 'b', 'c'] }, + { path: '....@a/#...)!&§[b.#§c..d....', expected: ['a', 'b', 'c', 'd'] }, + { path: '....@a/#...)!&§[b.#§c..dä....', expected: ['a', 'b', 'c', 'd'] } ])('normalizes path correctly', async ({ path, expected }) => { expect(normalizePagePath(path)).toStrictEqual(expected); }); diff --git a/src/features/settings/composables/useSettingsPage.js b/src/features/settings/composables/useSettingsPage.js index f97ca11..3af36ab 100644 --- a/src/features/settings/composables/useSettingsPage.js +++ b/src/features/settings/composables/useSettingsPage.js @@ -20,7 +20,10 @@ export const normalizePagePath = function normalizePagePath (path) { return path .replace(/\.+/g, '.') .replace(/^\.+|\.+$/g, '') - .split('.'); + .split('.') + .map( + (segment) => segment.replace(/[^a-zA-Z0-9-]/g, '') + ); }; export const useSettingsPage = function useSettingsPage () {