From cb93ef8144b10832b591a7e8c472cdd5d024a750 Mon Sep 17 00:00:00 2001 From: Kazuhiro NISHIYAMA Date: Tue, 5 Nov 2024 13:01:36 +0900 Subject: [PATCH] Fix bugs and improve (#152) * Remove unused @form_data * Change addr and peeraddr to non-nil * Fix typo of constant name * Improve split arguments --- lib/webrick/httpauth/authenticator.rb | 8 ++++---- lib/webrick/httpauth/htgroup.rb | 2 +- lib/webrick/httpauth/htpasswd.rb | 4 ++-- lib/webrick/httprequest.rb | 4 ++-- sig/httpauth/authenticator.rbs | 2 +- sig/httprequest.rbs | 6 ++---- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/webrick/httpauth/authenticator.rb b/lib/webrick/httpauth/authenticator.rb index a6ee28de..13b1c7e3 100644 --- a/lib/webrick/httpauth/authenticator.rb +++ b/lib/webrick/httpauth/authenticator.rb @@ -108,10 +108,10 @@ def info(fmt, *args) # authentication schemes for proxies. module ProxyAuthenticator - RequestField = "Proxy-Authorization" # :nodoc: - ResponseField = "Proxy-Authenticate" # :nodoc: - InfoField = "Proxy-Authentication-Info" # :nodoc: - AuthException = HTTPStatus::ProxyAuthenticationRequired # :nodoc: + RequestField = "Proxy-Authorization" # :nodoc: + ResponseField = "Proxy-Authenticate" # :nodoc: + ResponseInfoField = "Proxy-Authentication-Info" # :nodoc: + AuthException = HTTPStatus::ProxyAuthenticationRequired # :nodoc: end end end diff --git a/lib/webrick/httpauth/htgroup.rb b/lib/webrick/httpauth/htgroup.rb index 108c9d0b..df19b85b 100644 --- a/lib/webrick/httpauth/htgroup.rb +++ b/lib/webrick/httpauth/htgroup.rb @@ -49,7 +49,7 @@ def reload File.open(@path){|io| while line = io.gets line.chomp! - group, members = line.split(/:\s*/) + group, members = line.split(/:\s*/, 2) @group[group] = members.split(/\s+/) end } diff --git a/lib/webrick/httpauth/htpasswd.rb b/lib/webrick/httpauth/htpasswd.rb index 9a48e57d..db70125e 100644 --- a/lib/webrick/httpauth/htpasswd.rb +++ b/lib/webrick/httpauth/htpasswd.rb @@ -77,12 +77,12 @@ def reload if @password_hash == :bcrypt raise StandardError, ".htpasswd file contains crypt password, only bcrypt passwords supported" end - user, pass = line.split(":") + user, pass = line.split(":", 2) when %r!\A[^:]+:\$2[aby]\$\d{2}\$.{53}\z! if @password_hash == :crypt raise StandardError, ".htpasswd file contains bcrypt password, only crypt passwords supported" end - user, pass = line.split(":") + user, pass = line.split(":", 2) when /:\$/, /:{SHA}/ raise NotImplementedError, 'MD5, SHA1 .htpasswd file not supported' diff --git a/lib/webrick/httprequest.rb b/lib/webrick/httprequest.rb index 1fa5dbb4..2b50037e 100644 --- a/lib/webrick/httprequest.rb +++ b/lib/webrick/httprequest.rb @@ -162,7 +162,6 @@ def initialize(config) @script_name = @path_info = nil @query_string = nil @query = nil - @form_data = nil @raw_header = Array.new @header = nil @@ -173,7 +172,8 @@ def initialize(config) @accept_language = [] @body = +"" - @addr = @peeraddr = nil + @addr = [] + @peeraddr = [] @attributes = {} @user = nil @keep_alive = false diff --git a/sig/httpauth/authenticator.rbs b/sig/httpauth/authenticator.rbs index 394899d8..fe94762b 100644 --- a/sig/httpauth/authenticator.rbs +++ b/sig/httpauth/authenticator.rbs @@ -47,7 +47,7 @@ module WEBrick ResponseField: String - InfoField: String + ResponseInfoField: String AuthException: singleton(HTTPStatus::ClientError) end diff --git a/sig/httprequest.rbs b/sig/httprequest.rbs index 15a1f4c1..82c229e0 100644 --- a/sig/httprequest.rbs +++ b/sig/httprequest.rbs @@ -8,8 +8,6 @@ module WEBrick @query: Hash[String, HTTPUtils::FormData]? - @form_data: nil - @body: String @remaining_size: Integer? @@ -72,9 +70,9 @@ module WEBrick attr_accessor user: String? - attr_reader addr: ([String, Integer, String, String] | [])? + attr_reader addr: ([String, Integer, String, String] | []) - attr_reader peeraddr: ([String, Integer, String, String] | [])? + attr_reader peeraddr: ([String, Integer, String, String] | []) attr_reader attributes: Hash[untyped, untyped]