From 2b3dd84a13c0c9a43a8263fbc39fc989a5b87571 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 20 May 2026 22:54:59 +0800 Subject: [PATCH] fix: isWebBricksBackendResource() must extract path from full URLs before matching /public Bug: when fetchUi('/public') resolves to http://host:port/public, the isWebBricksBackendResource() check compared the full URL string against '/public' and always returned false, so _webbricks_=1 was never added. Fix: extract the path component from full URLs (strip scheme+host) before running the .ui/.dspy/public/root detection logic. All HTTP methods (getText/getJson/postJson/postForm) delegate to withBackendContextIfNeeded which calls isWebBricksBackendResource, so this fix covers all code paths. --- .../com/bricks/mp/core/WebBricksRequestContext.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/shared/src/commonMain/kotlin/com/bricks/mp/core/WebBricksRequestContext.kt b/shared/src/commonMain/kotlin/com/bricks/mp/core/WebBricksRequestContext.kt index 5aa6df1..045e5ae 100644 --- a/shared/src/commonMain/kotlin/com/bricks/mp/core/WebBricksRequestContext.kt +++ b/shared/src/commonMain/kotlin/com/bricks/mp/core/WebBricksRequestContext.kt @@ -54,9 +54,21 @@ fun withWebBricksRequestContext( * Detect URLs that need WebBricks backend context (_webbricks_=1). * Covers both direct .ui/.dspy paths and index fallback paths that the * server resolves to .ui files (e.g. "/" → index.ui, "/public" → index.ui). + * + * Handles both full URLs (http://host:port/public) and path-only strings (/public). */ fun String.isWebBricksBackendResource(): Boolean { - val path = substringBefore('?').substringBefore('#') + val withoutQuery = substringBefore('?').substringBefore('#') + + // Extract path component: strip scheme+host for full URLs, keep as-is for paths + val path = if (withoutQuery.contains("://")) { + // Full URL: find first '/' after "://" + val afterScheme = withoutQuery.substringAfter("://") + "/" + afterScheme.substringAfter('/', missingDelimiterValue = "") + } else { + withoutQuery + } + val normalized = path.trimEnd('/') // Direct .ui/.dspy resource