Skip to content

Empty DOM attribute crashes tokenizer #311

Description

@forthrin
require 'uri'
require 'net/http'

uri = URI('https://restaurangang.se/')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.response_body_encoding = true
http.send_request('GET', uri.path)

net-http-0.9.1/lib/net/http/response.rb:in 'Net::HTTPResponse#get_attribute': undefined method 'downcase!' for nil

Breakdown:

<!DOCTYPE html>
<title>Validating Document</title>
<meta charset="utf-8" data-next-head="">

@jeremyevans wrote on 2022-04-11 08:17:19 -0700 :

$ git blame -L528,538 response.rb 
case ss.peek(1)
when '"'
  ss.getch
  value = ss.scan(/[^"]+/)
  value.downcase!
  ss.getch

Works and passes rake test, but leaving to a seasoned dev what to ultimately commit.

diff --git a/lib/net/http/response.rb b/lib/net/http/response.rb
index 0b5b326..1fda33a 100644
--- a/lib/net/http/response.rb
+++ b/lib/net/http/response.rb
@@ -530,4 +530,3 @@ class Net::HTTPResponse
       ss.getch
-      value = ss.scan(/[^"]+/)
-      value.downcase!
+      value = (ss.scan(/[^"]+/) || '').downcase
       ss.getch
@@ -535,4 +534,3 @@ class Net::HTTPResponse
       ss.getch
-      value = ss.scan(/[^']+/)
-      value.downcase!
+      value = (ss.scan(/[^']+/) || '').downcase
       ss.getch
@@ -541,4 +539,3 @@ class Net::HTTPResponse
     else
-      value = ss.scan(/[^\t\n\f\r >]+/)
-      value.downcase!
+      value = ss.scan(/[^\t\n\f\r >]+/).downcase
     end
System Version: macOS 26.5.1 (25F80)
Model Identifier: MacBookAir10,1
ruby 4.0.5 (2026-05-20 revision 64336ffd0e) +PRISM [arm64-darwin25]
rubocop     2026-07-10 5e56132d8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions