SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
fix: fallback to raw param if decodeURIComponent fails for dashboard variables (#10695)
Ashwin Bhatkal234787f2c1a4
diff --git a/frontend/src/hooks/dashboard/__test__/useVariablesFromUrl.test.tsx b/frontend/src/hooks/dashboard/__test__/useVariablesFromUrl.test.tsxindex 1129221c10..32dd6cd18c 100644--- a/frontend/src/hooks/dashboard/__test__/useVariablesFromUrl.test.tsx+++ b/frontend/src/hooks/dashboard/__test__/useVariablesFromUrl.test.tsx@@ -226,6 +226,41 @@ describe('useVariablesFromUrl', () => {expect(urlVariables.undefinedVar).toBeUndefined();});+ it('should return empty object when URL param contains a bare % that makes decodeURIComponent throw', () => {+ // Simulate a URL where the variables param is a raw JSON string containing a literal %+ // (e.g. a metric value like "cpu_usage_50%"). URLSearchParams.get() returns the value+ // as-is when it was set directly; if it contains a bare %, decodeURIComponent throws a URIError.+ const rawJson = JSON.stringify({ threshold: '50%' });+ const history = createMemoryHistory({+ initialEntries: [`/?${QueryParams.variables}=${rawJson}`],+ });++ const { result } = renderHook(() => useVariablesFromUrl(), {+ wrapper: ({ children }: { children: React.ReactNode }) => (+ <Router history={history}>{children}</Router>+ ),+ });++ // Should parse successfully via the raw fallback, not throw or return {}+ const vars = result.current.getUrlVariables();+ expect(vars).toEqual({ threshold: '50%' });+ });++ it('should return empty object when URL param is completely unparseable', () => {+ // A value that fails both decodeURIComponent and JSON.parse+ const history = createMemoryHistory({+ initialEntries: [`/?${QueryParams.variables}=not-json-%ZZ`],+ });++ const { result } = renderHook(() => useVariablesFromUrl(), {+ wrapper: ({ children }: { children: React.ReactNode }) => (+ <Router history={history}>{children}</Router>+ ),+ });++ expect(result.current.getUrlVariables()).toEqual({});+ });+it('should update variables with array values correctly', () => {const history = createMemoryHistory({initialEntries: ['/'],diff --git a/frontend/src/hooks/dashboard/useVariablesFromUrl.tsx b/frontend/src/hooks/dashboard/useVariablesFromUrl.tsxindex c08c179025..c263c6c3f5 100644--- a/frontend/src/hooks/dashboard/useVariablesFromUrl.tsx+++ b/frontend/src/hooks/dashboard/useVariablesFromUrl.tsx@@ -32,7 +32,14 @@ const useVariablesFromUrl = (): UseVariablesFromUrlReturn => {}try {- return JSON.parse(decodeURIComponent(variablesParam));+ const decoded = ((): string => {+ try {+ return decodeURIComponent(variablesParam);+ } catch {+ return variablesParam;+ }+ })();+ return JSON.parse(decoded);} catch (error) {Sentry.captureEvent({message: `Failed to parse dashboard variables from URL: ${error}`,