Actions
Bug #9563
closedURI.parse error
Description
I have the error for the url :
... pry(main)> URI.parse "http://upload.wikimedia.org/wikipedia/commons/1/1c/01-Russian_alphabet-А_а.svg" URI::InvalidURIError: bad URI(is not URI?): http://upload.wikimedia.org/wikipedia/commons/1/1c/01-Russian_alphabet-А_а.svg
My ruby version is:
$ ruby -v ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin13.0]
Updated by srawlins (Sam Rawlins) over 10 years ago
You must first encode the String properly with URI.escape:
>> require 'uri'
=> true
>> URI.escape("http://upload.wikimedia.org/wikipedia/commons/1/1c/01-Russian_alphabet-А_а.svg")
=> "http://upload.wikimedia.org/wikipedia/commons/1/1c/01-Russian_alphabet-%D0%90_%D0%B0.svg"
>> URI.parse(URI.escape("http://upload.wikimedia.org/wikipedia/commons/1/1c/01-Russian_alphabet-А_а.svg"))
=> #<URI::HTTP:0x007fbe4304e468 URL:http://upload.wikimedia.org/wikipedia/commons/1/1c/01-Russian_alphabet-%D0%90_%D0%B0.svg>
>> URI.parse(URI.escape("http://upload.wikimedia.org/wikipedia/commons/1/1c/01-Russian_alphabet-А_а.svg")).to_s
=> "http://upload.wikimedia.org/wikipedia/commons/1/1c/01-Russian_alphabet-%D0%90_%D0%B0.svg"
This could be better documented.
Updated by zzak (zzak _) over 10 years ago
- Category set to doc
- Status changed from Open to Assigned
- Assignee set to zzak (zzak _)
- Target version set to 2.2.0
Updated by zzak (zzak _) over 10 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100
Applied in changeset r46984.
- lib/uri/common.rb: [DOC] [Bug #9563] Recommend using URI.escape
before parsing a uri to avoid invalid characters. Reported by
Evgeniy Serykh.
Actions
Like0
Like0Like0Like0