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

AddQueryParameter : Pipe character still encoded with false option #2207

Open
ronando82 opened this issue May 27, 2024 · 2 comments · May be fixed by #2208
Open

AddQueryParameter : Pipe character still encoded with false option #2207

ronando82 opened this issue May 27, 2024 · 2 comments · May be fixed by #2208
Labels

Comments

@ronando82
Copy link

ronando82 commented May 27, 2024

Describe the bug
i use AddQueryParameter with false attribute to prevent encoding my string but it doesn't work.

Example : .AddQueryParameter("ids", "in:001|116", false);

To Reproduce

var clientRest = new RestClient("http://xxx.yyy");
string resource = "/v1/xxxx/;
var request = new RestRequest(resource, Method.Get)
    .AddHeader("Accept", "application/json")
    .AddHeader("x-api-key", "myapikey")  
    **.AddQueryParameter("ids", "in:001|116", false);**

var responseRest =  clientRest.GetAsync<string>(request).Result;

the transmitted parameter is: ids=in:001**%7C**116

For example it's work with a slash / instead a pipe character |

    .AddQueryParameter("ids", "in:001/116", false);

the transmitted parameter is: ids=in:001/C116

Expected behavior

i would expect not encoding the pipe character

Desktop (please complete the following information):

  • OS: windows 11
  • .NET version 4.8
  • Version 111.1.0
@ronando82 ronando82 added the bug label May 27, 2024
@alexeyzimarev alexeyzimarev linked a pull request May 27, 2024 that will close this issue
3 tasks
@alexeyzimarev
Copy link
Member

RestSharp doesn't encode query parameters when it is told not to. For example, this simple test passes:

    [Fact]
    public void Should_not_encode_pipe() {
        var client = new RestClient("http://example.com");
        var request = new RestRequest("resource");
        request.AddQueryParameter("ids", "in:001|116", false);
        
        var actual = client.BuildUri(request);
        var expected = new Uri("http://example.com/resource?ids=in:001|116");
        actual.Should().Be(expected);
    }

However, what I found now is that the Uri object encodes the pipe character. So, the actual URI values in both expected and actual vars in the test contain the same string with encoded pipe char, where the original URL string property for both of them contain non-encoded values.

I fixe in my PR but for .NET < 6 the code uses an obsolete Uri ctor. It works, just hoping they won't remove it.

@alexeyzimarev
Copy link
Member

Sorry, closed prematurely. It still has issues with how some characters are encoded, it's different per framework. Will look at it again soon.

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

Successfully merging a pull request may close this issue.

2 participants