Project

General

Profile

Actions

Feature #15378

closed

URI::InvalidURIError (bad URI(is not URI?)

Added by ipatovanton (Anton Ipatov) over 5 years ago. Updated over 2 years ago.

Status:
Third Party's Issue
Assignee:
-
Target version:
-
[ruby-core:90284]

Description

I using the ruby 2.5.3 and try to save this url http://zapovednik.space/material/stantsija-petropavlovsk

URI::InvalidURIError (bad URI(is not URI?):
http://zapovednik.space/material/stantsija-petropavlovsk):

class FeedEntry
  field :url, type: String

  before_create :save_uri

  def save_uri
    self.url = URI(self.url).tap { |uri| uri.query = nil }.to_s
  end
end

Trace:

/Users/ipatov/.rbenv/versions/2.5.3/lib/ruby/2.5.0/uri/rfc3986_parser.rb:67:in `split'
/Users/ipatov/.rbenv/versions/2.5.3/lib/ruby/2.5.0/uri/rfc3986_parser.rb:73:in `parse'
/Users/ipatov/.rbenv/versions/2.5.3/lib/ruby/2.5.0/uri/common.rb:237:in `parse'
/Users/ipatov/.rbenv/versions/2.5.3/lib/ruby/2.5.0/uri/common.rb:743:in `URI'
app/models/feed_entry.rb:54:in `save_uri'
activesupport (5.2.1.1) lib/active_support/callbacks.rb:426:in `block in make_lambda'
activesupport (5.2.1.1) lib/active_support/callbacks.rb:198:in `block (2 levels) in halting'
activesupport (5.2.1.1) lib/active_support/callbacks.rb:606:in `block (2 levels) in default_terminator'
activesupport (5.2.1.1) lib/active_support/callbacks.rb:605:in `catch'
activesupport (5.2.1.1) lib/active_support/callbacks.rb:605:in `block in default_terminator'
activesupport (5.2.1.1) lib/active_support/callbacks.rb:199:in `block in halting'
activesupport (5.2.1.1) lib/active_support/callbacks.rb:513:in `block in invoke_before'
activesupport (5.2.1.1) lib/active_support/callbacks.rb:513:in `each'
activesupport (5.2.1.1) lib/active_support/callbacks.rb:513:in `invoke_before'
activesupport (5.2.1.1) lib/active_support/callbacks.rb:131:in `run_callbacks'

Updated by shyouhei (Shyouhei Urabe) over 5 years ago

  • Status changed from Open to Feedback

Can I ask you the exact representation of the self.url parameter, not just its printable part? I guess it contains control character, most likely newlines.

just add raise self.uri.inspect right before the line you are getting the exception now, and tell us the verbatim output.

Updated by ipatovanton (Anton Ipatov) over 5 years ago

RuntimeError ("\nhttp://zapovednik.space/material/stantsija-petropavlovsk"):

Updated by shyouhei (Shyouhei Urabe) over 5 years ago

  • Description updated (diff)
  • Status changed from Feedback to Third Party's Issue

ipatovanton (Anton Ipatov) wrote:

RuntimeError ("\nhttp://zapovednik.space/material/stantsija-petropavlovsk"):

Thank you!

The problem is the "\n" at the very beginning of self.url. This is in fact a bad URI.
To fix this, please remove that before calling URI().

Updated by ipatovanton (Anton Ipatov) over 5 years ago

Thank you!

What do you think is the problem with the encoding?

Updated by shyouhei (Shyouhei Urabe) over 5 years ago

ipatovanton (Anton Ipatov) wrote:

Thank you!

What do you think is the problem with the encoding?

As far as I can see from the info you gave us, it seems the problem has nothing to do with encodings.

Actions #6

Updated by hsbt (Hiroshi SHIBATA) over 2 years ago

  • Project changed from 14 to Ruby master
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0