From e444525ef1634b675cd1cf52d39f4320ef0aecfd Mon Sep 17 00:00:00 2001
From: Mike Dalessio <mike.dalessio@gmail.com>
Date: Sun, 10 Apr 2022 14:42:04 -0400
Subject: [PATCH] fix(perf): HTML4::EncodingReader detection

---
 lib/nokogiri/html4/document.rb       |  2 +-
 test/html4/test_document_encoding.rb | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/lib/nokogiri/html4/document.rb b/lib/nokogiri/html4/document.rb
index 177efc04f..fbc22d207 100644
--- a/lib/nokogiri/html4/document.rb
+++ b/lib/nokogiri/html4/document.rb
@@ -268,7 +268,7 @@ def start_element(name, attrs = [])
         end
 
         def self.detect_encoding(chunk)
-          (m = chunk.match(/\A(<\?xml[ \t\r\n]+[^>]*>)/)) &&
+          (m = chunk.match(/\A(<\?xml[ \t\r\n][^>]*>)/)) &&
             (return Nokogiri.XML(m[1]).encoding)
 
           if Nokogiri.jruby?
