-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
A method to escape a string into uri safe structure #3515
A method to escape a string into uri safe structure #3515
Conversation
it looks like Crystal URI.escape has the same behaviour as URI.encode_www_form_component in Ruby. why not copy Ruby? it has:
|
Ruby's
I agree that the relation between Ruby's implementation and mine is very confusing. |
👍 |
I wouldn't mind keeping "Ruby compatibility". I'm not sure I understand why so many methods are needed. I see: URI.escape("https://crystal-lang.org") # => https://crystal-lang.org (I need this!) Isn't that just the original string? In which case it would make a difference? |
Or, another question, when do you need the behaviour of Ruby's |
parts of uri paths usually escaped like this: ruby URI.escape '/bla-жж/'
=> "/bla-%D0%B6%D0%B6/" crystal URI.escape '/bla-жж/'
=> %2Fbla-%D0%B6%D0%B6%2F" |
right now crystal URI.escape = CGI.escape, and no method for URI parts escape |
Although I'm quite aware of that and that there are some actual use-cases for |
@5t111111 Thank you for the link! I was also having a hard time imagining a use case for this. For example:
|
when you parse uri from html, for example, need to normalize it (escape, and ...) |
Another scenario besides creating a URI from individual components is encoding a string which is not directly used in a URI. URI encoding is also relevant for other applications like sending HTTP POST data as We need the following transformations for strings:
These should be implement in two different methods called
Please note that there are different rules for URI encoding with slight differences. I think it is sufficient to implement only the most recent RFC 3986 (but keep the option to encode space as |
@tbrand Are you still up for this? |
I think we should do something about this. We should have a distinction between encoding an URI (Ruby's Also worth noting is that in Ruby, So... I guess I don't know. But following what Elixir does seems good and safe. |
IIRC I have a branch with a new implementation laying around. I think it was delayed because I did the URI normalize stuff first. |
* Adds methods URI.encode and URI.decode for URL encoding without escaping reserved characters. * URI.escape and URI.unescape are renamed to URI.encode_www_form and URI.decode_www_form. All these methods have been moved to a separate file in `src/uri/encoding.cr` to clean up the main file. They're an isolated domain just live in URI's class namespace. Method names have been chosen according to the names of other APIs, especially Elixir's (see crystal-lang#3515 (comment)).
* Adds methods URI.encode and URI.decode for URL encoding without escaping reserved characters. * URI.escape and URI.unescape are renamed to URI.encode_www_form and URI.decode_www_form. All these methods have been moved to a separate file in `src/uri/encoding.cr` to clean up the main file. They're an isolated domain just live in URI's class namespace. Method names have been chosen according to the names of other APIs, especially Elixir's (see crystal-lang#3515 (comment)).
* Adds methods URI.encode and URI.decode for URL encoding without escaping reserved characters. * URI.escape and URI.unescape are renamed to URI.encode_www_form and URI.decode_www_form. All these methods have been moved to a separate file in `src/uri/encoding.cr` to clean up the main file. They're an isolated domain just live in URI's class namespace. Method names have been chosen according to the names of other APIs, especially Elixir's (see crystal-lang#3515 (comment)).
* Adds methods URI.encode and URI.decode for URL encoding without escaping reserved characters. * URI.escape and URI.unescape are renamed to URI.encode_www_form and URI.decode_www_form. All these methods have been moved to a separate file in `src/uri/encoding.cr` to clean up the main file. They're an isolated domain just live in URI's class namespace. Method names have been chosen according to the names of other APIs, especially Elixir's (see crystal-lang#3515 (comment)).
* Adds methods URI.encode and URI.decode for URL encoding without escaping reserved characters. * URI.escape and URI.unescape are renamed to URI.encode_www_form and URI.decode_www_form. All these methods have been moved to a separate file in `src/uri/encoding.cr` to clean up the main file. They're an isolated domain just live in URI's class namespace. Method names have been chosen according to the names of other APIs, especially Elixir's (see crystal-lang#3515 (comment)).
Hi there,
There is a critical difference between Ruby and Crystal for an implementation of URI.escape.
Then,
So it is difficult to escape a String in uri-safe structure like as Ruby's behavior.
So I added a method to keep the String url structure.
Then,
May be this issue is involved.
Thanks for your review.