Project

General

Profile

Actions

Bug #12498

closed

Parsing a mailto URI with no recipient throws the error URI::InvalidComponentError: missing opaque part for mailto URL

Added by cheister (Chris Heisterkamp) almost 8 years ago. Updated over 7 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
[ruby-core:76055]

Description

If you try to parse a mailto URI without a recipient you get an error. For example

ruby -ruri -e 'URI.parse("mailto:?subject=hi")'

will throw the error:

/usr/lib/ruby/2.3.0/uri/mailto.rb:140:in initialize': missing opaque part for mailto URL (URI::InvalidComponentError) from /usr/lib/ruby/2.3.0/uri/rfc3986_parser.rb:76:in new'
from /usr/lib/ruby/2.3.0/uri/rfc3986_parser.rb:76:in parse' from /usr/lib/ruby/2.3.0/uri/common.rb:227:in parse'
from -e:1:in `'

This is similar to the issue https://bugs.ruby-lang.org/issues/12212 and is caused by the combination of https://bugs.ruby-lang.org/issues/10738 and https://bugs.ruby-lang.org/issues/2542

When the URI Lib was updated to use the RFC 3986 parser it does not always return the @opaque part of the URI. So the check added in https://bugs.ruby-lang.org/issues/10738 will always fail.

The fix uses the @query part returned from the new parser if the @opaque part is not defined. Here are examples of the differences between the parts returned by the new and old parser

scheme, userinfo, host, port, registry, path, opaque, query, fragment = URI::RFC2396_Parser.new.split('mailto:?to=&subject=hey!')
=> ["mailto", nil, nil, nil, nil, nil, "?to=&subject=hey!", nil, nil]
opaque
=> "?to=&subject=hey!"

scheme, userinfo, host, port, registry, path, opaque, query, fragment = URI::RFC3986_Parser.new.split('mailto:?to=&subject=hey!')
=> ["mailto", nil, nil, nil, nil, "", nil, "to=&subject=hey!", nil]
opaque
=> nil
query
=> "to=&subject=hey!"


Files

fix_empty_mailto_recipient_parsing.patch (1.79 KB) fix_empty_mailto_recipient_parsing.patch cheister (Chris Heisterkamp), 06/16/2016 07:31 PM

Updated by duerst (Martin Dürst) almost 8 years ago

I agree this is a bug. The syntax at http://tools.ietf.org/html/rfc6068#section-2 clearly makes the 'to' part optional.

Updated by cheister (Chris Heisterkamp) almost 8 years ago

  • Assignee set to naruse (Yui NARUSE)

@naruse (Yui NARUSE) Do you mind taking a look at this patch?

Actions #3

Updated by naruse (Yui NARUSE) almost 8 years ago

  • Status changed from Open to Closed

Applied in changeset r55563.


Updated by usa (Usaku NAKAMURA) over 7 years ago

  • Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.1: WONTFIX, 2.2: REQUIRED, 2.3: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) over 7 years ago

  • Backport changed from 2.1: WONTFIX, 2.2: REQUIRED, 2.3: REQUIRED to 2.1: WONTFIX, 2.2: REQUIRED, 2.3: DONE

ruby_2_3 r55916 merged revision(s) 55563.

Updated by usa (Usaku NAKAMURA) over 7 years ago

  • Backport changed from 2.1: WONTFIX, 2.2: REQUIRED, 2.3: DONE to 2.1: WONTFIX, 2.2: DONE, 2.3: DONE

ruby_2_2 r55941 merged revision(s) 55563.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0