From: merch-redmine@... Date: 2020-10-30T15:32:09+00:00 Subject: [ruby-core:100672] [Ruby master Bug#17293] URI.parse fails to parse correctly URN or other special characters in path/url 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/ Unsubscribe: