Skip to content

[csharp][generichost] Concatenation can produce invalid url #23262

@devhl-labs

Description

@devhl-labs

P2: Path concatenation can produce a double-slash when BaseAddress.AbsolutePath ends with '/', resulting in a different URL path (e.g., /api//widgets/{id}) that may not match server routes.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Api/DefaultApi.cs, line 236:

<comment>Path concatenation can produce a double-slash when BaseAddress.AbsolutePath ends with '/', resulting in a different URL path (e.g., /api//widgets/{id}) that may not match server routes.</comment>

<file context>
@@ -0,0 +1,383 @@
+                    uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme;
+                    uriBuilderLocalVar.Path = HttpClient.BaseAddress.AbsolutePath == "/"
+                        ? "/widgets/{id}"
+                        : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/widgets/{id}");
+                    uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7Bid%7D", Uri.EscapeDataString(id.ToString()));
+
</file context>
Fix with Cubic

Originally posted by @cubic-dev-ai[bot] in #23260 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions