Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

“path” parameters are URL encoded differently in Java than in C# #151

Closed
ThomasMarquardt opened this issue Feb 26, 2018 · 7 comments
Closed

Comments

@ThomasMarquardt
Copy link

Using AutoRest 2.0.4245, I noticed that “path” parameters are URL encoded differently in Java than in C# (Swagger below). In Java, “dir/file” is encoded as “dir%2Ffile”. In C#, it is encoded as “dir/file”. I like the way C# encodes paths and would like URL encoding to be consistent across the languages.

{
  "swagger": "2.0",
  "info": {
    "description": "Test URL encoding.",
    "title": "Test",
    "version": "2018-02-18"
  },
  "host": "localhost",
  "schemes": [
    "http",
    "https"
  ],
  "paths": {
    "/{path}": {
      "get": {
        "operationId": "GetPath",
        "description": "Test Path Parameter.",
        "responses": {
          "200": {
            "description": "Test"
          }
        }
      },
      "parameters": [
        {
          "name": "path",
          "in": "path",
          "description": "The path to test.",
          "required": true,
          "type": "string"
        }
      ]
    }
  }
}
@RikkiGibson RikkiGibson self-assigned this Feb 26, 2018
@RikkiGibson
Copy link
Member

RikkiGibson commented Feb 27, 2018

I can't reproduce this behavior with .NET Core 2.0 on my Mac. When I generate the C# client with:

[email protected]/autorest.csharp@latest

and pass a URL parameter like abc/123$@, I see abc%2F123%24%40%23 in my debugging proxy.

Will follow up after I try to repro on my PC.

@RikkiGibson
Copy link
Member

I also see %2F instead of / in Fiddler when I run with .NET Core 2 on Windows. @ThomasMarquardt please double check whether the client you generated had x-ms-skip-url-encoding or not. Let me know if you have any idea of what could explain the difference in behavior between our environments.

It's not likely we'll support this unless I can find someone on the C# side who can tell me they definitely are skipping encoding /, and the fact that / is getting encoded in my environment is a bug.

@shahabhijeet do you know what the expected behavior of URL encoding '/' with the C# runtime is?

@ThomasMarquardt
Copy link
Author

I made a mistake, and both C# and Java are incorrectly encoding /. C# is calling System.Uri.EscapeDataString(path) but it should be calling System.Uri.EscapeUriString(path) because path is a parameter in the URI.

@RikkiGibson
Copy link
Member

I've been looking around to try and make sure of what the spec is supposed to be. It appears that by default we need to escape slashes in path params. It sounds like C# and Java are doing this. Feel free to follow up with any suggestions if "x-ms-skip-url-encoding" is not enough to address your use case.

swagger-api/swagger-js#280
OAI/OpenAPI-Specification#892

@ThomasMarquardt
Copy link
Author

Sorry, what I said in my previous post is incorrect. Although C# uses System.Uri.EscapeDataString to escape path parameters, and the / character is encoded as %2F by that call, later when the request is sent across the wire the URL has / character--it is not encoded. Java, on the other hand, sends it as %2F. This is a problem for us.

@RikkiGibson
Copy link
Member

It would be of great help to us if you could provide a sample project which reproduces the C# runtime behavior you describe.

@RikkiGibson RikkiGibson removed their assignment Aug 12, 2020
@jianghaolu
Copy link
Contributor

If you want to skip URL encoding for a path parameter, please use x-ms-skip-url-encoding as Rikki suggested above. See https://github.com/Azure/autorest/tree/main/docs/extensions#x-ms-skip-url-encoding for details and examples.

If this is still an issue with x-ms-skip-url-encoding added, please feel free to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants