Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Fix broken v1 filters redirect (#5941)

Artur Patae4b282a6105b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 80627ae6ef..f58ec5a373 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,7 +13,8 @@ All notable changes to this project will be documented in this file.
### Fixed
- To make internal stats API requests for password-protected shared links, shared link auth cookie must be set in the requests
-- Fix issue with site guests in Editor role and team members in Editor role not being able to change the domain of site
+- Fixed issue with site guests in Editor role and team members in Editor role not being able to change the domain of site
+- Fixed direct dashboard links that use legacy dashboard filters containing URL encoded special characters (e.g. character `ê` in the legacy filter `?page=%C3%AA`)
## v3.1.0 - 2025-11-13
diff --git a/assets/js/dashboard/util/url-search-params-v1.ts b/assets/js/dashboard/util/url-search-params-v1.ts
index 08d14aa238..88843081f3 100644
--- a/assets/js/dashboard/util/url-search-params-v1.ts
+++ b/assets/js/dashboard/util/url-search-params-v1.ts
@@ -40,21 +40,22 @@ const LEGACY_URL_PARAMETERS = {
exit_page: null
}
-function isV1(searchRecord: Record<string, unknown>): boolean {
- return Object.keys(searchRecord).some(
- (k) => k === 'props' || LEGACY_URL_PARAMETERS.hasOwnProperty(k)
- )
+function isV1(searchParams: URLSearchParams): boolean {
+ for (const k of searchParams.keys()) {
+ if (k === 'props' || LEGACY_URL_PARAMETERS.hasOwnProperty(k)) {
+ return true
+ }
+ }
+ return false
}
-function parseSearchRecord(
- searchRecord: Record<string, unknown>
-): Record<string, unknown> {
- const searchRecordEntries = Object.entries(searchRecord)
+function parseSearch(searchString: string): Record<string, unknown> {
+ const searchParams = new URLSearchParams(searchString)
const updatedSearchRecordEntries = []
const filters: Filter[] = []
let labels: DashboardQuery['labels'] = {}
- for (const [key, value] of searchRecordEntries) {
+ for (const [key, value] of searchParams.entries()) {
if (LEGACY_URL_PARAMETERS.hasOwnProperty(key)) {
if (typeof value !== 'string') {
continue
@@ -63,9 +64,10 @@ function parseSearchRecord(
filters.push(filter)
const labelsKey: string | null | undefined =
LEGACY_URL_PARAMETERS[key as keyof typeof LEGACY_URL_PARAMETERS]
- if (labelsKey && searchRecord[labelsKey]) {
+ const labelsParamValue = labelsKey ? searchParams.get(labelsKey) : null
+ if (labelsParamValue) {
const clauses = filter[2]
- const labelsValues = (searchRecord[labelsKey] as string)
+ const labelsValues = labelsParamValue
.split('|')
.filter((label) => !!label)
const newLabels = Object.fromEntries(
@@ -79,8 +81,9 @@ function parseSearchRecord(
}
}
- if (typeof searchRecord['props'] === 'string') {
- filters.push(...(parseLegacyPropsFilter(searchRecord['props']) as Filter[]))
+ const propsParamValue = searchParams.get('props')
+ if (typeof propsParamValue === 'string') {
+ filters.push(...(parseLegacyPropsFilter(propsParamValue) as Filter[]))
}
updatedSearchRecordEntries.push(['filters', filters], ['labels', labels])
return Object.fromEntries(updatedSearchRecordEntries)
@@ -114,5 +117,5 @@ function parseLegacyPropsFilter(rawValue: string) {
export const v1 = {
isV1,
- parseSearchRecord
+ parseSearch
}
diff --git a/assets/js/dashboard/util/url-search-params.test.ts b/assets/js/dashboard/util/url-search-params.test.ts
index 9ac792d768..91ecbb6b28 100644
--- a/assets/js/dashboard/util/url-search-params.test.ts
+++ b/assets/js/dashboard/util/url-search-params.test.ts
@@ -242,21 +242,25 @@ describe(`${getRedirectTarget.name}`, () => {
).toBeNull()
})
- it('returns updated URL for page=... style filters (v1), and running the updated value through the function again returns null (no redirect loop)', () => {
- const pathname = '/'
- const search = '?page=/docs'
- const expectedUpdatedSearch = '?f=is,page,/docs&r=v1'
- expect(
- getRedirectTarget({
- pathname,
- search
- } as Location)
- ).toEqual(`${pathname}${expectedUpdatedSearch}`)
- expect(
- getRedirectTarget({
- pathname,
- search: expectedUpdatedSearch
- } as Location)
- ).toBeNull()
- })
+ it.each([
+ ['?page=/docs', '?f=is,page,/docs&r=v1'],
+ ['?page=%C3%AA&embed=true', '?f=is,page,%C3%AA&embed=true&r=v1']
+ ])(
+ 'returns updated URL v1 style filter %s, and running the updated value through the function again returns null (no redirect loop)',
+ (searchString, expectedSearchString) => {
+ const pathname = '/'
+ expect(
+ getRedirectTarget({
+ pathname,
+ search: searchString
+ } as Location)
+ ).toEqual(`${pathname}${expectedSearchString}`)
+ expect(
+ getRedirectTarget({
+ pathname,
+ search: expectedSearchString
+ } as Location)
+ ).toBeNull()
+ }
+ )
})
diff --git a/assets/js/dashboard/util/url-search-params.ts b/assets/js/dashboard/util/url-search-params.ts
index 1ade67ed80..be8ce5d9a0 100644
--- a/assets/js/dashboard/util/url-search-params.ts
+++ b/assets/js/dashboard/util/url-search-params.ts
@@ -241,18 +241,17 @@ export function getRedirectTarget(windowLocation: Location): null | string {
}
const isV2 = v2.isV2(searchParams)
+ const isV1 = v1.isV1(searchParams)
+
if (isV2) {
return `${windowLocation.pathname}${stringifySearch({ ...v2.parseSearch(windowLocation.search), [REDIRECTED_SEARCH_PARAM_NAME]: 'v2' })}`
}
- const searchRecord = v2.parseSearch(windowLocation.search)
- const isV1 = v1.isV1(searchRecord)
-
- if (!isV1) {
- return null
+ if (isV1) {
+ return `${windowLocation.pathname}${stringifySearch({ ...v1.parseSearch(windowLocation.search), [REDIRECTED_SEARCH_PARAM_NAME]: 'v1' })}`
}
- return `${windowLocation.pathname}${stringifySearch({ ...v1.parseSearchRecord(searchRecord), [REDIRECTED_SEARCH_PARAM_NAME]: 'v1' })}`
+ return null
}
/** Called once before React app mounts. If legacy url search params are present, does a redirect to new format. */