From 17b50cdb68ce016caee0d6fef8e8438a5bf5addb Mon Sep 17 00:00:00 2001 From: Jenny Shen Date: Sun, 23 Jul 2023 19:18:44 -0400 Subject: [PATCH] [rubygems/rubygems] Add charset to Webauthn response content-type https://github.com/rubygems/rubygems/commit/442a3e8f37 --- .../gemcutter_utilities/webauthn_listener/response.rb | 2 +- test/rubygems/test_webauthn_listener.rb | 6 +++--- test/rubygems/test_webauthn_listener_response.rb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb b/lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb index c0e2778485..7709a8fef3 100644 --- a/lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb +++ b/lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb @@ -81,7 +81,7 @@ module Gem::GemcutterUtilities def add_body return unless body - @http_response["content-type"] = "text/plain" + @http_response["content-type"] = "text/plain; charset=utf-8" @http_response["content-length"] = body.bytesize @http_response.instance_variable_set(:@body, body) end diff --git a/test/rubygems/test_webauthn_listener.rb b/test/rubygems/test_webauthn_listener.rb index 45745eb935..5e91064b49 100644 --- a/test/rubygems/test_webauthn_listener.rb +++ b/test/rubygems/test_webauthn_listener.rb @@ -55,7 +55,7 @@ class WebauthnListenerTest < Gem::TestCase response = Gem::MockBrowser.get URI("http://localhost:#{@port}?code=xyz") assert response.is_a? Net::HTTPOK - assert_equal "text/plain", response["Content-Type"] + assert_equal "text/plain; charset=utf-8", response["Content-Type"] assert_equal "7", response["Content-Length"] assert_equal Gem.host, response["access-control-allow-origin"] assert_equal "POST", response["access-control-allow-methods"] @@ -96,7 +96,7 @@ class WebauthnListenerTest < Gem::TestCase response = Gem::MockBrowser.get URI("http://localhost:#{@port}") assert response.is_a? Net::HTTPBadRequest - assert_equal "text/plain", response["Content-Type"] + assert_equal "text/plain; charset=utf-8", response["Content-Type"] assert_equal "22", response["Content-Length"] assert_equal "close", response["Connection"] assert_equal "missing code parameter", response.body @@ -110,7 +110,7 @@ class WebauthnListenerTest < Gem::TestCase response = Gem::MockBrowser.get URI("http://localhost:#{@port}?param=xyz") assert response.is_a? Net::HTTPBadRequest - assert_equal "text/plain", response["Content-Type"] + assert_equal "text/plain; charset=utf-8", response["Content-Type"] assert_equal "22", response["Content-Length"] assert_equal "close", response["Connection"] assert_equal "missing code parameter", response.body diff --git a/test/rubygems/test_webauthn_listener_response.rb b/test/rubygems/test_webauthn_listener_response.rb index ce617ebada..377e5bfe5a 100644 --- a/test/rubygems/test_webauthn_listener_response.rb +++ b/test/rubygems/test_webauthn_listener_response.rb @@ -18,7 +18,7 @@ class WebauthnListenerResponseTest < Gem::TestCase access-control-allow-origin: rubygems.example\r access-control-allow-methods: POST\r access-control-allow-headers: Content-Type, Authorization, x-csrf-token\r - content-type: text/plain\r + content-type: text/plain; charset=utf-8\r content-length: 7\r \r success @@ -82,7 +82,7 @@ class WebauthnListenerResponseTest < Gem::TestCase access-control-allow-origin: rubygems.example\r access-control-allow-methods: POST\r access-control-allow-headers: Content-Type, Authorization, x-csrf-token\r - content-type: text/plain\r + content-type: text/plain; charset=utf-8\r content-length: 22\r \r missing code parameter