Project

General

Profile

Actions

Bug #16830

closed

URI.parse raises NoMethodError instead of URI::InvalidURIError

Added by csk157 (Česlovas Lopan) over 4 years ago. Updated over 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]
[ruby-core:98138]

Description

When parsing an invalid uri using URI.parse it is possible to get NoMethodError (undefined method []' for nil:NilClass). I would expect URI::InvalidURIError` or similar.

Example with a trace:

irb(main):002:0> URI.parse("ldaps:https://example.com")
Traceback (most recent call last):
       10: from /Users/clopan/.rbenv/versions/2.7.1/bin/irb:23:in `<main>'
        9: from /Users/clopan/.rbenv/versions/2.7.1/bin/irb:23:in `load'
        8: from /Users/clopan/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/irb-1.2.3/exe/irb:11:in `<top (required)>'
        7: from (irb):1
        6: from (irb):2:in `rescue in irb_binding'
        5: from /Users/clopan/.rbenv/versions/2.7.1/lib/ruby/2.7.0/uri/common.rb:234:in `parse'
        4: from /Users/clopan/.rbenv/versions/2.7.1/lib/ruby/2.7.0/uri/rfc3986_parser.rb:76:in `parse'
        3: from /Users/clopan/.rbenv/versions/2.7.1/lib/ruby/2.7.0/uri/rfc3986_parser.rb:76:in `new'
        2: from /Users/clopan/.rbenv/versions/2.7.1/lib/ruby/2.7.0/uri/ldap.rb:116:in `initialize'
        1: from /Users/clopan/.rbenv/versions/2.7.1/lib/ruby/2.7.0/uri/ldap.rb:122:in `parse_dn'
NoMethodError (undefined method `[]' for nil:NilClass)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0