Issue #12212 has been updated by jeremyevans0 (Jeremy Evans).

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.

----------------------------------------
Bug #12212: Parsing a URI of "mailto:?subject=hi" with `URI.parse` raises an exception
https://bugs.ruby-lang.org/issues/12212#change-78897

* Author: madeofcode (Mark Dodwell)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: trunk
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
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:

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

Behavior expected:

```ruby
>> 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--------------------------------
fix-uri-mailto-parsing-blank-to-with-query.patch (1.52 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>