Bug #9563

URI.parse error

Added by Evgeniy Serykh about 1 year ago. Updated 9 months ago.

[ruby-core:61078]
Status:Closed
Priority:Normal
Assignee:Zachary Scott
ruby -v:ruby 2.1.0p0 (2013-12-25 revision 44422) Backport:1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN

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]

Associated revisions

Revision 46984
Added by Zachary Scott 9 months ago

  • lib/uri/common.rb: [DOC] [Bug #9563] Recommend using URI.escape before parsing a uri to avoid invalid characters. Reported by Evgeniy Serykh.

Revision 46984
Added by Zachary Scott 9 months ago

  • lib/uri/common.rb: [DOC] [Bug #9563] Recommend using URI.escape before parsing a uri to avoid invalid characters. Reported by Evgeniy Serykh.

History

#1 Updated by Sam Rawlins about 1 year 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.

#2 Updated by Zachary Scott about 1 year ago

  • Status changed from Open to Assigned
  • Assignee set to Zachary Scott
  • Category set to doc
  • Target version set to current: 2.2.0

#3 Updated by Zachary Scott 9 months 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.

Also available in: Atom PDF