{"record":{"id":"1414f1baa5232f9d","repo":"ruby/ruby","slug":"missing-opaque-part-for-mailto-url","errorCode":null,"errorMessage":"missing opaque part for mailto URL","messagePattern":"missing opaque part for mailto URL","errorType":"exception","errorClass":"InvalidComponentError","httpStatus":null,"severity":"error","filePath":"lib/uri/mailto.rb","lineNumber":142,"sourceCode":"    # == Description\n    #\n    # Creates a new URI::MailTo object from generic URL components with\n    # no syntax checking.\n    #\n    # This method is usually called from URI::parse, which checks\n    # the validity of each component.\n    #\n    def initialize(*arg)\n      super(*arg)\n\n      @to = nil\n      @headers = []\n\n      # The RFC3986 parser does not normally populate opaque\n      @opaque = \"?#{@query}\" if @query && !@opaque\n\n      unless @opaque\n        raise InvalidComponentError,\n          \"missing opaque part for mailto URL\"\n      end\n      to, header = @opaque.split('?', 2)\n      # allow semicolon as a addr-spec separator\n      # http://support.microsoft.com/kb/820868\n      unless /\\A(?:[^@,;]+@[^@,;]+(?:\\z|[,;]))*\\z/ =~ to\n        raise InvalidComponentError,\n          \"unrecognised opaque part for mailtoURL: #{@opaque}\"\n      end\n\n      if arg[10] # arg_check\n        self.to = to\n        self.headers = header\n      else\n        set_to(to)\n        set_headers(header)\n      end\n    end","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/ruby/ruby/blob/0e5b888e1c355f3f728f2659f085820937dada48/lib/uri/mailto.rb#L124-L160","documentation":"URI::Mailto must carry an opaque part holding the addr-spec; the RFC 3986 parser does not populate opaque for mailto, so initialize derives it from the query or expects it set. With neither opaque nor query — i.e., no address at all — initialize raises InvalidComponentError 'missing opaque part for mailto URL'.","triggerScenarios":"URI('mailto:'); URI::Mailto.build([nil, nil]); URI::Mailto.new with all blank components — the classic producer is URI(\"mailto:#{email}\") with email nil or empty.","commonSituations":"Building mailto links from optional form fields; templates rendering mailto with an empty address variable; contact forms where the email param is missing.","solutions":["Skip link generation when the address is blank","Build with a real address: URI::Mailto.build(['user@example.com', 'subject=Hi'])","Presence-validate the email before any URI parsing"],"exampleFix":"# before\nuri = URI(\"mailto:#{params[:email]}\")   # params[:email] nil -> \"mailto:\"\n# InvalidComponentError: missing opaque part for mailto URL\n\n# after\nemail = params[:email].to_s.strip\nreturn if email.empty?\nuri = URI(\"mailto:#{email}\")","handlingStrategy":"validation","validationCode":"def mailto_uri(email)\n  email = email.to_s.strip\n  return nil if email.empty?\n  URI(\"mailto:#{email}\")\nend","typeGuard":null,"tryCatchPattern":"begin\n  URI(\"mailto:#{email}\")\nrescue URI::InvalidComponentError\n  nil # blank address -> no link\nend","preventionTips":["Presence-check the email before building any mailto link","Centralize mailto creation in one helper that returns nil for blanks","Prefer skip-rendering over fallback text when the address is missing"],"tags":["ruby","uri","mailto","email","missing-opaque"],"backgroundTag":"invalid-mailto-uri","analyzedSha":"0e5b888e1c355f3f728f2659f085820937dada48","analyzedAt":"2026-08-21T14:25:43.473Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}