From b1841bb7184f709c6afd7eb80baccd06f7a33048 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Sat, 11 Jul 2026 09:54:48 -0700 Subject: [PATCH] Handle quoted content-type charset parameter values Additionally, as all related strings are new objects, use ! methods to reduce allocations. Remove unnecessary * before param.split, as param.split already returns an array. Fixes #267 --- lib/net/http/header.rb | 12 ++++++++++-- test/net/http/test_httpheader.rb | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/net/http/header.rb b/lib/net/http/header.rb index 6106e79..b5c13cc 100644 --- a/lib/net/http/header.rb +++ b/lib/net/http/header.rb @@ -773,8 +773,16 @@ def type_params list = self['Content-Type'].to_s.split(';') list.shift list.each do |param| - k, v = *param.split('=', 2) - result[k.strip] = v.strip + k, v = param.split('=', 2) + k.strip! + v.strip! + v.gsub!(/\A"(.*?)(? 'iso-2022-jp'}, @c.type_params) @c.content_type = 'text' assert_equal({}, @c.type_params) + @c['content-type'] = 'text/html; charset="UTF\-8"' + assert_equal({'charset' => 'UTF-8'}, @c.type_params) end def test_set_content_type