Skip to content

URI::MailTo.build does not percent-encode addresses (contrary to RFC 6068) #238

Open

Description

@amomchilov

URI::MailTo raises InvalidComponentError when given these special symbols, which RFC 6068, section 2 requires be percent-encoded.

URI::MailTo.build(to: "#!$%&'*+-/=?^_`{}|@example.org")
# unrecognised opaque part for mailtoURL: #!$%&'*+-/=?^_`{}|@example.org (URI::InvalidComponentError)
# expected: mailto:%23%21%24%25%26%27%2A%2B-%2F%3D%3F%5E_%60%7B%7D%7C@example.org
  • For reference, see this PR which implemented this behaviour in Rails' ActionView (though Rails has its own URI generation logic, and doesn't use URI::MailTo).
  • This logic was last changed back in 2014 in 3fdc4b6

Activity

  1. sourya2704 commented on Oct 18, 2026

    @sourya2704

    I'd like to work on this if nobody else is.

    One thing to settle first: build currently passes to through as already-encoded, e.g. build(to: "a%2Bb@example.org") gives mailto:a%2Bb@example.org. If build starts encoding everything, that input would become a%252Bb, which breaks anyone escaping on their side.

    My plan is to percent-encode only the characters that aren't allowed in to, and leave existing %XX sequences alone, so current callers keep working. A literal % that isn't followed by two hex digits would become %25. Does that sound OK, or would you rather have an option/new method for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions