Git Product home page Git Product logo

Comments (6)

johncmckim avatar johncmckim commented on July 22, 2024

Is the issue with the entire link or encoding the parameters that are substituted into the link? Can you provide examples?

from halcyon.

NiklasArbin avatar NiklasArbin commented on July 22, 2024

With the entire link:

new Link("self", "api/categories/1/this should be url encoded/", null, "GET"),

from halcyon.

johncmckim avatar johncmckim commented on July 22, 2024

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.

NiklasArbin avatar NiklasArbin commented on July 22, 2024

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.

johncmckim avatar johncmckim commented on July 22, 2024

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.

NiklasArbin avatar NiklasArbin commented on July 22, 2024

I still see this when we add Links using the templates. Maybe I need to check the newer version?

from halcyon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.