Project

General

Profile

Actions

Bug #12212

closed

Parsing a URI of "mailto:?subject=hi" with `URI.parse` raises an exception

Added by madeofcode (Mark Dodwell) about 8 years ago. Updated almost 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:74527]

Description

Parsing a URI of "mailto:?subject=hi" with URI.parse raises an exception. I believe this is a valid "mailto" URI, as defined in RFC6068.

Behavior observed:

>> URI.parse("mailto:?subject=hi")
NoMethodError: undefined method `split' for nil:NilClass

Behavior expected:

>> uri = URI.parse("mailto:?subject=hi")
=> #<URI::MailTo URL:mailto:?subject=hi>
>> uri.to
=> ""
>> uri.headers
=> [["subject", "hi"]]

Reference from RFC6068 than defines the "to" element as optional:

mailtoURI = "mailto:" [ to ] [ hfields ]

https://tools.ietf.org/html/rfc6068#section-2

Patch attached.


Files

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

Mark Dodwell wrote:

Parsing a URI of "mailto:?subject=hi" with URI.parse raises an exception. I believe this is a valid "mailto" URI, as defined in RFC6068.

As one of the co-authors of RFC 6068, I have to agree with you. See the first syntax production in https://tools.ietf.org/html/rfc6068#section-2, where the square brackets around 'to' in
mailtoURI = "mailto:" [ to ] [ hfields ]
indicate that the 'to' part can be omitted. This rule is exactly the same as in RFC 2368
(see https://tools.ietf.org/html/rfc2368#section-2), the predecessor of RFC 6068.

Although most 'mailto' URIs will have a 'to' part, it can clearly be useful to have a 'mailto' URI without a 'to' part, e.g. if only cc: and bcc: addressees are present, or for some sample emails where e.g. 'subject' and body are prepared, but each user has to enter the addressees themselves.

Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago

  • Status changed from Open to Closed

I can't replicate the NoMethodError you are receiving on any ruby version:

$ ruby18 -ruri -e 'p URI.parse("mailto:?subject=hi")'
#<URI::MailTo:0xab543e6f5c0 URL:mailto:?subject=hi>
$ ruby19 -ruri -e 'p URI.parse("mailto:?subject=hi")'
#<URI::MailTo:0x000ccbbd117f98 URL:mailto:?subject=hi>
$ ruby20 -ruri -e 'p URI.parse("mailto:?subject=hi")'
#<URI::MailTo:0x000af32a635038 URL:mailto:?subject=hi>
$ ruby21 -ruri -e 'p URI.parse("mailto:?subject=hi")'
#<URI::MailTo:0x000054409bb308 URL:mailto:?subject=hi>
$ ruby22 -ruri -e 'p URI.parse("mailto:?subject=hi")'
#<URI::MailTo mailto:?subject=hi>
$ ruby23 -ruri -e 'p URI.parse("mailto:?subject=hi")'
#<URI::MailTo mailto:?subject=hi>
$ ruby24 -ruri -e 'p URI.parse("mailto:?subject=hi")'
#<URI::MailTo mailto:?subject=hi>
$ ruby25 -ruri -e 'p URI.parse("mailto:?subject=hi")'
#<URI::MailTo mailto:?subject=hi>
$ ruby26 -ruri -e 'p URI.parse("mailto:?subject=hi")'
#<URI::MailTo mailto:?subject=hi>

In the patch, the regexp you are trying to skip (/\A(?:[^@,;]+@[^@,;]+(?:\z|[,;]))*\z/) already matches the empty string, and skipping the conditional would prevent a InvalidComponentError, it wouldn't affect the NoMethodError you received.

Actions

Also available in: Atom PDF

Like0
Like0Like0