From 8520f1e2b7d20c48b1f20f6b5dd7aeacfb5e0599 Mon Sep 17 00:00:00 2001 From: sgayangi Date: Fri, 14 Nov 2025 11:47:15 +0530 Subject: [PATCH 1/3] Fix bug in basepath and path contatenation --- .../internal/oasparser/model/adapter_internal_api.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/adapter/internal/oasparser/model/adapter_internal_api.go b/adapter/internal/oasparser/model/adapter_internal_api.go index 7310c1e8b..52d100b06 100644 --- a/adapter/internal/oasparser/model/adapter_internal_api.go +++ b/adapter/internal/oasparser/model/adapter_internal_api.go @@ -726,9 +726,9 @@ func (adapterInternalAPI *AdapterInternalAPI) SetInfoHTTPRouteCR(ctx context.Con switch filter.URLRewrite.Path.Type { case gwapiv1.FullPathHTTPPathModifier: - policyParameters[constants.RewritePathResourcePath] = backendBasePath + *filter.URLRewrite.Path.ReplaceFullPath + policyParameters[constants.RewritePathResourcePath] = joinPaths(backendBasePath, *filter.URLRewrite.Path.ReplaceFullPath) case gwapiv1.PrefixMatchHTTPPathModifier: - policyParameters[constants.RewritePathResourcePath] = backendBasePath + *filter.URLRewrite.Path.ReplacePrefixMatch + policyParameters[constants.RewritePathResourcePath] = joinPaths(backendBasePath, *filter.URLRewrite.Path.ReplacePrefixMatch) } policies.Request = append(policies.Request, Policy{ @@ -2151,6 +2151,14 @@ func CreateDummyAdapterInternalAPIForTests(title, version, basePath string, reso } } +// joinPaths safely concatenates basePath and path, avoiding double slashes when basePath is "/" +func joinPaths(basePath, path string) string { + if basePath == "/" { + return path + } + return basePath + path +} + func prepareAIRatelimitIdentifier(org string, namespacedName types.NamespacedName, spec *dpv1alpha3.AIRateLimitPolicySpec) string { targetNamespace := string(namespacedName.Namespace) if spec.TargetRef.Namespace != nil && string(*spec.TargetRef.Namespace) != "" { From d094cba16dba4b7d2a8e102c161c05ea83361e57 Mon Sep 17 00:00:00 2001 From: sgayangi Date: Fri, 14 Nov 2025 11:54:28 +0530 Subject: [PATCH 2/3] Bump helm chart version --- helm-charts/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm-charts/Chart.yaml b/helm-charts/Chart.yaml index 3470a6d53..bb2cc9708 100644 --- a/helm-charts/Chart.yaml +++ b/helm-charts/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: choreo-apk description: A Helm chart for APK components type: application -version: 1.3.0-24 +version: 1.3.0-25 appVersion: "1.3.0" dependencies: - name: postgresql From e2ff150eb14c3853ba872606d4e8ad2189e14705 Mon Sep 17 00:00:00 2001 From: sgayangi Date: Fri, 14 Nov 2025 14:22:58 +0530 Subject: [PATCH 3/3] Improve concatenation for backend basepaths --- .../oasparser/model/adapter_internal_api.go | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/adapter/internal/oasparser/model/adapter_internal_api.go b/adapter/internal/oasparser/model/adapter_internal_api.go index 52d100b06..0084f7f4f 100644 --- a/adapter/internal/oasparser/model/adapter_internal_api.go +++ b/adapter/internal/oasparser/model/adapter_internal_api.go @@ -879,9 +879,9 @@ func (adapterInternalAPI *AdapterInternalAPI) SetInfoHTTPRouteCR(ctx context.Con switch filter.RequestRedirect.Path.Type { case gwapiv1.FullPathHTTPPathModifier: - policyParameters[constants.RedirectPath] = backendBasePath + *filter.RequestRedirect.Path.ReplaceFullPath + policyParameters[constants.RedirectPath] = joinPaths(backendBasePath, *filter.RequestRedirect.Path.ReplaceFullPath) case gwapiv1.PrefixMatchHTTPPathModifier: - policyParameters[constants.RedirectPath] = backendBasePath + *filter.RequestRedirect.Path.ReplacePrefixMatch + policyParameters[constants.RedirectPath] = joinPaths(backendBasePath, *filter.RequestRedirect.Path.ReplacePrefixMatch) } requestRedirectEndpoint.Basepath = policyParameters[constants.RedirectPath].(string) @@ -1019,14 +1019,14 @@ func (adapterInternalAPI *AdapterInternalAPI) SetInfoHTTPRouteCR(ctx context.Con policyParameters[constants.RewritePathType] = gwapiv1.FullPathHTTPPathModifier } policyParameters[constants.IncludeQueryParams] = true - policyParameters[constants.RewritePathResourcePath] = strings.TrimSuffix(backendBasePath, "/") + *match.Path.Value + policyParameters[constants.RewritePathResourcePath] = joinPaths(backendBasePath, *match.Path.Value) policies.Request = append(policies.Request, Policy{ PolicyName: string(gwapiv1.HTTPRouteFilterURLRewrite), Action: constants.ActionRewritePath, Parameters: policyParameters, }) } - resourcePath := adapterInternalAPI.xWso2Basepath + *match.Path.Value + resourcePath := joinPaths(adapterInternalAPI.xWso2Basepath, *match.Path.Value) matchID := getMatchID(httpRoute.Namespace, httpRoute.Name, ruleID, matchID) operations := getAllowedOperations(matchID, match.Method, policies, apiAuth, parseRateLimitPolicyToInternal(resourceRatelimitPolicy), scopes, mirrorEndpointClusters) @@ -2151,11 +2151,38 @@ func CreateDummyAdapterInternalAPIForTests(title, version, basePath string, reso } } -// joinPaths safely concatenates basePath and path, avoiding double slashes when basePath is "/" +// joinPaths safely concatenates basePath and path, handling various edge cases func joinPaths(basePath, path string) string { + // Trim spaces from both inputs + basePath = strings.TrimSpace(basePath) + path = strings.TrimSpace(path) + + // Handle empty basePath + if basePath == "" { + return path + } + + // Handle empty path + if path == "" { + return basePath + } + + // If basePath is just "/", return the path as is to avoid "//" prefix if basePath == "/" { return path } + + // Handle case where path doesn't start with "/" but basePath doesn't end with "/" + // This ensures proper path formation + if !strings.HasSuffix(basePath, "/") && !strings.HasPrefix(path, "/") { + return basePath + "/" + path + } + + // Handle double slash case where basePath ends with "/" and path starts with "/" + if strings.HasSuffix(basePath, "/") && strings.HasPrefix(path, "/") { + return basePath + strings.TrimPrefix(path, "/") + } + return basePath + path }