Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of Uri.ToString() in JsonHttpClient in ServiceStack

In the following code of JsonHttpClient.cs of ServiceStack library the absoluteUrl is malformed:

absoluteUrl = new Uri(absoluteUrl).ToString();

For example, if absoluteUrl contains a value of:

https://somedomain/imagestream?locationCode=TitelDia&relativePath=Marketing%20en%20Sales&fileName=M%26S_titel_1.jpeg

then after executing the code line, the absoluteUrl contains value:

https://somedomain/imagestream?locationCode=TitelDia&relativePath=Marketing en Sales&fileName=M&S_titel_1.jpeg

Note that %20 and %26 are changed to the canonical values as documented in the Microsoft documentation.

The unescaped canonical representation of the Uri instance. All characters are unescaped except #, ?, and %.

Others are also complaining about the usage of uri.ToString() and that its usage is almost certain a bug.

Is the usage of uri.ToString() in ServiceStack indeed a bug and it should be changed to AbsoluteUri?

This behavior causes unwanted behavior on the server side, because the malformed url / query string is sent to the server. The value of fileName on the server is 'M' instead of 'M&S_titel_1.jpg'.

like image 706
Robin Bouwmeester Avatar asked Sep 07 '25 15:09

Robin Bouwmeester


1 Answers

I've just replaced usages of Uri.ToString() to Uri.AbsoluteUri in this commit as suggested.

This change is available from v8.8.1+ that's now available in pre-release packages

like image 130
mythz Avatar answered Sep 10 '25 08:09

mythz