diff --git a/adapter/internal/oasparser/model/adapter_internal_api.go b/adapter/internal/oasparser/model/adapter_internal_api.go index 7310c1e8b..0084f7f4f 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{ @@ -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,6 +2151,41 @@ func CreateDummyAdapterInternalAPIForTests(title, version, basePath string, reso } } +// 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 +} + func prepareAIRatelimitIdentifier(org string, namespacedName types.NamespacedName, spec *dpv1alpha3.AIRateLimitPolicySpec) string { targetNamespace := string(namespacedName.Namespace) if spec.TargetRef.Namespace != nil && string(*spec.TargetRef.Namespace) != "" { 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