Comments (6)
Is the issue with the entire link or encoding the parameters that are substituted into the link? Can you provide examples?
from halcyon.
With the entire link:
new Link("self", "api/categories/1/this should be url encoded/", null, "GET"),
from halcyon.
Encoding the entire link presents an issue. System.Uri.EscapeUriString
is good for encoding a whole URL. However, fails pretty badly if a query string is involved. System.Uri.EscapeDataString
doesn't work well for a whole URL, but is good for encoding components.
See these examples
System.Uri.EscapeDataString("api/foo bar/test"); // api%2Ffoo%20bar%2Ftest - bad. double encoded.
System.Uri.EscapeUriString("api/foo bar/test"); // api/foo%20bar/test - good
HttpUtility.UrlEncode("api/foo bar/test"); // api%2ffoo+bar%2ftest - bad. double encoded.
System.Uri.EscapeDataString("api/foo bar/test?q=happy+cat"); // api%2Ffoo%20bar%2Ftest%3Fq%3Dhappy%2Bcat - bad. double encoded.
System.Uri.EscapeUriString("api/foo bar/test?q=happy+cat"); // api/foo%20bar/test?q=happy+cat - bad. plus sign not encoded.
HttpUtility.UrlEncode("api/foo bar/test?q=happy+cat"); // api%2ffoo+bar%2ftest%3fq%3dhappy%2bcat - bad for url. good for happy%2bcat component
System.Uri.EscapeDataString("api/foo bar/test?q=father&son"); // api%2Ffoo%20bar%2Ftest%3Fq%3Dfather%26son - bad
System.Uri.EscapeUriString("api/foo bar/test?q=father&son"); // api/foo%20bar/test?q=father&son - bad. ampersand not encoded.
HttpUtility.UrlEncode("api/foo bar/test?q=father&son"); // api%2ffoo+bar%2ftest%3fq%3dfather%26son - bad for url. good for father%26son component
System.Uri.EscapeDataString("api/foo bar/test?q=one%20two"); // api%2Ffoo%20bar%2Ftest%3Fq%3Done%2520two - bad. double encoded.
System.Uri.EscapeUriString("api/foo bar/test?q=one%20two"); // api/foo%20bar/test?q=one%2520two - bad. double encoded.
HttpUtility.UrlEncode("api/foo bar/test?q=one%20two"); // api%2ffoo+bar%2ftest%3fq%3done%2520two - bad. double encoded.
This presents a pretty big issue for trying to encode the entire link. Encoding parts of the link with System.Uri.EscapeDataString
will work well. In your example, you can easily hard code the escaped string. Whereas, it would be a pain to encode the templated variables. So while I agree that Halcyon should help with URL encoding, I think ti should just be limited to encoding the variables before replacing them.
Do you have any thoughts on this? Do you know of other methods in .NET that would handle this in a better way? Keeping in mind that it should work with .NET and .NET Core.
from halcyon.
You are right, I just assumed there was an easy way of doing this for the entire URI.
Our actual use case is for parameters, since all other parts can be controlled in other ways. Would you consider adding UrlEncode for parameters (per parameter)?
The class System.Net.WebUtility is .Net Core compliant.
from halcyon.
I just added some tests for this issue. It looks like the URI template library that I am using already URL Encodes the parameters. See this test file. Can you please test again to confirm the issue?
from halcyon.
I still see this when we add Links using the templates. Maybe I need to check the newer version?
from halcyon.
Related Issues (20)
- Object that inherit public properties cannot be used in parameter substitution HOT 1
- Embedded Attribute should add non IEnumerable properties as Resources and not Collections
- Accept Header Not Working HOT 3
- Output is not using camel case
- Response Content-Type is always "application/json"
- Are there any plans to support XML serialisation? HOT 1
- Unable to return non-HAL results after disabling default JsonOutputFormatter HOT 5
- JsonHalOutputFormatter does not implement IApiResponseTypeMetadataProvider HOT 1
- Serializer settings should also be used when explicitly passed in HOT 2
- JsonHalOutputFormatter doesn't support IHALConverter
- Unexpected output when using HALAttributeConverter HOT 1
- Allow passing of default HALModelConfig to HALAttributeConverter
- HALAttributeConverter does not handle null values for HalEmbedded properties
- Collection example HOT 4
- How to return URI templates in links? HOT 3
- OData not working with HALResponse
- Getting the mebedded recousres with the correct Links
- How can I accurately represent the dto that will be returned to a REST call with Swagger? HOT 2
- Exception adding OutputFormatter in .netcore 3.0 HOT 4
- halcyon is not working on the .Net 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from halcyon.