ruby-changes:72186
From: Shishir <ko1@a...>
Date: Thu, 16 Jun 2022 20:17:14 +0900 (JST)
Subject: [ruby-changes:72186] 63546bfc15 (master): HTTPHeader.content_range throws error on non-byte units
https://git.ruby-lang.org/ruby.git/commit/?id=63546bfc15 From 63546bfc1581d4abec2a0d846106a1c0afc0efa9 Mon Sep 17 00:00:00 2001 From: Shishir Joshi <shishir127@u...> Date: Thu, 16 Jun 2022 16:46:47 +0530 Subject: HTTPHeader.content_range throws error on non-byte units * Added a nil check in Net::HTTPHeader#initialize_http_header for keys in the header that do not have any value * Returning nil from the content_range method instead of raising an error when the unit in the content-range header is not bytes * Modified initialize_http_header to match trunk fix [Bug #11450] fix https://github.com/ruby/ruby/pull/1018 --- lib/net/http/header.rb | 4 ++-- test/net/http/test_httpheader.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/net/http/header.rb b/lib/net/http/header.rb index a8901e79cb..e96d62732a 100644 --- a/lib/net/http/header.rb +++ b/lib/net/http/header.rb @@ -338,8 +338,8 @@ module Net::HTTPHeader https://github.com/ruby/ruby/blob/trunk/lib/net/http/header.rb#L338 # fits inside the full entity body, as range of byte offsets. def content_range return nil unless @header['content-range'] - m = %r<bytes\s+(\d+)-(\d+)/(\d+|\*)>i.match(self['Content-Range']) or - raise Net::HTTPHeaderSyntaxError, 'wrong Content-Range format' + m = %r<bytes\s+(\d+)-(\d+)/(\d+|\*)>i.match(self['Content-Range']) + return nil if m.nil? m[1].to_i .. m[2].to_i end diff --git a/test/net/http/test_httpheader.rb b/test/net/http/test_httpheader.rb index cfbe36bcfd..20ffd91beb 100644 --- a/test/net/http/test_httpheader.rb +++ b/test/net/http/test_httpheader.rb @@ -308,6 +308,14 @@ class HTTPHeaderTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/http/test_httpheader.rb#L308 end def test_content_range + @c['Content-Range'] = "bytes 0-499/1000" + assert_equal 0..499, @c.content_range + @c['Content-Range'] = "bytes 1-500/1000" + assert_equal 1..500, @c.content_range + @c['Content-Range'] = "bytes 1-1/1000" + assert_equal 1..1, @c.content_range + @c['Content-Range'] = "tokens 1-1/1000" + assert_equal nil, @c.content_range end def test_range_length @@ -317,6 +325,8 @@ class HTTPHeaderTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/http/test_httpheader.rb#L325 assert_equal 500, @c.range_length @c['Content-Range'] = "bytes 1-1/1000" assert_equal 1, @c.range_length + @c['Content-Range'] = "tokens 1-1/1000" + assert_equal nil, @c.range_length end def test_chunked? -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/