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

Unable to use the string '%2F' in a url parameter #2267

Open
cg-finbourne opened this issue Sep 24, 2024 · 2 comments
Open

Unable to use the string '%2F' in a url parameter #2267

cg-finbourne opened this issue Sep 24, 2024 · 2 comments
Labels

Comments

@cg-finbourne
Copy link

cg-finbourne commented Sep 24, 2024

Describe the bug
We need to use parameters with the characters '%2F' in them. After the change to src/RestSharp/Parameters/Parameter.cs in 4ddda24, which changed the Value property of the Parameter record from having an init set accessor to having no set accessor, we are unable to do this since there is no way to override the regex logic performed on the value in the UrlSegmentParameter constructor. Previously we were doing the following to set the Value property to the desired value

var paramValue = "foo%2fbar";
var param1 = new UrlSegmentParameter("foo", paramValue);
Console.WriteLine(param1); // outputs foo=foo/bar (undesired)
var param2 = param1 with {Value = paramValue};
Console.WriteLine(param2); // outputs foo=foo%2fbar (desired)

We are unable to use a different class for this parameter due to this line https://github.com/restsharp/RestSharp/blob/dev/src/RestSharp/Request/UriExtensions.cs#L57

To Reproduce
Steps to reproduce the behavior, preferably using a code snippet.
Post the non-working request here as well if you made it work using Postman, Swagger, or any other client.

See that this code does not compile:

new UrlSegmentParameter("foo", "foo%2fbar") { Value = "foo%2fbar" };

and new UrlSegmentParameter("foo", "foo%2fbar") results in a parameter with a Value of foo/bar

Expected behavior
A clear and concise description of what you expected to happen.
Post the working request here as well if you made it work using Postman, Swagger, or any other client.
You can use https://requestbin.com/r to create a public request bin and share the link in the issue.

We should be able to use a path parameter that includes '%2F' or '%2f'. I have a pull request for a suggested fix here #2265

Stack trace
Copy the full stack trace here if you get an exception.

Desktop (please complete the following information):

  • OS: [e.g. macOS]
  • .NET version [e.g. .NET 6]
  • Version [e.g. 110.2.0]

macOS .NET 8

Additional context
Add any other context about the problem here.

@alexeyzimarev
Copy link
Member

Why do you encode the parameter value? RestSharp will do it for you. Have you tried providing plain-text value instead?

@cg-finbourne
Copy link
Author

cg-finbourne commented Sep 30, 2024

Why do you encode the parameter value? RestSharp will do it for you. Have you tried providing plain-text value instead?

we have a use case where the path parameter needs to contain the sequence '%2F' literally, which when encoded will be '%252F'.

As an example:

'/foo/bar/test%252Ftest' is what we want to end up calling, rather than '/foo/bar/test%2Ftest' or '/foo/bar/test/test'

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

No branches or pull requests

2 participants