Empty DOM attribute crashes tokenizer

Open Beginner friendly
#311 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
ruby
Domain
networking

Research direction

Review lib/net/http/response.rb at get_attribute and reproduce the failure with the provided request containing an empty attribute. Run rake test and confirm that parsing this response no longer raises, adding regression coverage if the existing test structure supports it.

Written by the indexing model from the issue text.

Description

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
Dominant language
Ruby
Stars
148
Forks
95
Avg merge
10h 54m
Merged PRs (30d)
4

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ruby/net-http

All issues in ruby/net-http

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.