This is an automated email from the ASF dual-hosted git repository.
hainenber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 816794b1985 fix(frontend): handle null/undefined path in ensureAppRoot
(#39940)
816794b1985 is described below
commit 816794b19859eac8cf235b8b206baf7310d9dea1
Author: Abdul Rehman <[email protected]>
AuthorDate: Sat May 23 11:22:27 2026 +0500
fix(frontend): handle null/undefined path in ensureAppRoot (#39940)
Co-authored-by: Đỗ Trọng Hải <[email protected]>
---
superset-frontend/src/utils/pathUtils.test.ts | 14 ++++++++++++++
superset-frontend/src/utils/pathUtils.ts | 11 +++++++++--
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/superset-frontend/src/utils/pathUtils.test.ts
b/superset-frontend/src/utils/pathUtils.test.ts
index f89aa01ed1a..117e8eceab9 100644
--- a/superset-frontend/src/utils/pathUtils.test.ts
+++ b/superset-frontend/src/utils/pathUtils.test.ts
@@ -245,3 +245,17 @@ test('makeUrl should be idempotent with subdirectory
prefix', async () => {
const twice = makeUrl(once);
expect(twice).toBe(once); // /superset/sqllab?new=true, NOT
/superset/superset/sqllab?new=true
});
+
+test('ensureAppRoot should fall back to application root when path is null or
undefined', async () => {
+ const { ensureAppRoot } = await loadPathUtils('/superset/');
+
+ expect(ensureAppRoot(null)).toBe('/superset');
+ expect(ensureAppRoot(undefined)).toBe('/superset');
+});
+
+test('ensureAppRoot should fall back to "/" when path is null and no
application root is configured', async () => {
+ const { ensureAppRoot } = await loadPathUtils();
+
+ expect(ensureAppRoot(null)).toBe('/');
+ expect(ensureAppRoot(undefined)).toBe('/');
+});
diff --git a/superset-frontend/src/utils/pathUtils.ts
b/superset-frontend/src/utils/pathUtils.ts
index 477766e1313..b86faec2063 100644
--- a/superset-frontend/src/utils/pathUtils.ts
+++ b/superset-frontend/src/utils/pathUtils.ts
@@ -35,12 +35,19 @@ const SAFE_ABSOLUTE_URL_RE = /^(https?|ftp|mailto|tel):/i;
* Potentially dangerous schemes such as javascript: and data: are not treated
* as absolute and will be prefixed.
*
+ * If `path` is null or undefined, it falls back to the application root so the
+ * caller (e.g. partial theme overrides leaving brand tokens unset) doesn't
+ * crash.
+ *
* @param path A string path or URL to a resource
*/
-export function ensureAppRoot(path: string): string {
- if (SAFE_ABSOLUTE_URL_RE.test(path) || path.startsWith('//')) {
+export function ensureAppRoot(path: string | null | undefined): string {
+ if (path && (SAFE_ABSOLUTE_URL_RE.test(path) || path.startsWith('//'))) {
return path;
}
+ if (path == null) {
+ return applicationRoot() || '/';
+ }
const root = applicationRoot();
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
if (