* [ruby-core:100667] [Ruby master Bug#17293] URI.parse fails to parse correctly URN or other special characters in path/url
@ 2020-10-30 14:58 greg.howdeshell
2020-10-30 15:32 ` [ruby-core:100672] " merch-redmine
0 siblings, 1 reply; 2+ messages in thread
From: greg.howdeshell @ 2020-10-30 14:58 UTC (permalink / raw
To: ruby-core
Issue #17293 has been reported by greg.howdeshell (Greg Howdeshell).
----------------------------------------
Bug #17293: URI.parse fails to parse correctly URN or other special characters in path/url
https://bugs.ruby-lang.org/issues/17293
* Author: greg.howdeshell (Greg Howdeshell)
* Status: Open
* Priority: Normal
* ruby -v: 2.6.x
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
URI.parse looks to fail parsing endpoints that have special characters. For example:
``` ruby
url = 'http://foobar.com/#/applications/'
path = 'my_application'
URI.join(url, path).to_s
```
The result renders `http://foobar.com/my_application`.
Or in the case of executing an API marked by URNs so the ID field in my GET request is something like
```ruby
key = 'urn:api:baz:1'
url = 'http://foobar.com/api'
URI.join(url, key).to_s
```
The result renders `urn:api:baz:1`.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 2+ messages in thread
* [ruby-core:100672] [Ruby master Bug#17293] URI.parse fails to parse correctly URN or other special characters in path/url
2020-10-30 14:58 [ruby-core:100667] [Ruby master Bug#17293] URI.parse fails to parse correctly URN or other special characters in path/url greg.howdeshell
@ 2020-10-30 15:32 ` merch-redmine
0 siblings, 0 replies; 2+ messages in thread
From: merch-redmine @ 2020-10-30 15:32 UTC (permalink / raw
To: ruby-core
Issue #17293 has been updated by jeremyevans0 (Jeremy Evans).
Status changed from Open to Rejected
greg.howdeshell (Greg Howdeshell) wrote:
> URI.parse looks to fail parsing endpoints that have special characters. For example:
>
> ``` ruby
> url = 'http://foobar.com/#/applications/'
> path = 'my_application'
> URI.join(url, path).to_s
> ```
> The result renders `http://foobar.com/my_application`.
This is expected. The `#/applications/` is an anchor/fragment, not part of the path (path is `/`). For `my_application`, that is interpreted as the path, so it overwrites the path of the `url`. You get the same result for `URI.join('http://foobar.com/', 'my_application').to_s`.
>
> Or in the case of executing an API marked by URNs so the ID field in my GET request is something like
>
> ```ruby
> key = 'urn:api:baz:1'
> url = 'http://foobar.com/api'
> URI.join(url, key).to_s
> ```
> The result renders `urn:api:baz:1`.
The issue here is that `'urn:api:baz:1'` is interpreted as a URI with scheme `urn` and opaque part `api:baz:1`, which overrides the entire url.
The `URI.join` documents the behavior: `String(s) to work with, will be converted to RFC3986 URIs before merging.`.
You probably don't want to use `URI.join` in either example. You may want something like the following, but I'm not even sure of what URIs you are trying to generate:
```ruby
url = 'http://foobar.com/#/applications/'
path = 'my_application'
uri = URI.parse(url)
uri.fragment += path
uri.to_s
# => "http://foobar.com/#/applications/my_application"
key = 'urn:api:baz:1'
url = 'http://foobar.com/api'
uri = URI.parse(url)
uri.query = "ID=#{key}"
uri.to_s
# => "http://foobar.com/api?ID=urn:api:baz:1"
```
----------------------------------------
Bug #17293: URI.parse fails to parse correctly URN or other special characters in path/url
https://bugs.ruby-lang.org/issues/17293#change-88308
* Author: greg.howdeshell (Greg Howdeshell)
* Status: Rejected
* Priority: Normal
* ruby -v: 2.6.x
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
URI.parse looks to fail parsing endpoints that have special characters. For example:
``` ruby
url = 'http://foobar.com/#/applications/'
path = 'my_application'
URI.join(url, path).to_s
```
The result renders `http://foobar.com/my_application`.
Or in the case of executing an API marked by URNs so the ID field in my GET request is something like
```ruby
key = 'urn:api:baz:1'
url = 'http://foobar.com/api'
URI.join(url, key).to_s
```
The result renders `urn:api:baz:1`.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-10-30 15:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-30 14:58 [ruby-core:100667] [Ruby master Bug#17293] URI.parse fails to parse correctly URN or other special characters in path/url greg.howdeshell
2020-10-30 15:32 ` [ruby-core:100672] " merch-redmine
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).