Empty DOM attribute crashes tokenizer

Aperta Adatta ai principianti
#311 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
ruby
Ambito
networking

Direzione di ricerca

Esamina lib/net/http/response.rb in get_attribute e riproduci il malfunzionamento con la richiesta fornita contenente un attributo vuoto. Esegui rake test e verifica che l’analisi di questa risposta non generi più un’eccezione, aggiungendo una copertura di regressione se la struttura di test esistente lo consente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Ruby
Stelle
148
Fork
95
Merge medio
10h 54m
PR unite (30g)
4

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby/net-http

Tutte le issue di ruby/net-http

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.