ruby-changes:57990
From: Jeremy <ko1@a...>
Date: Fri, 27 Sep 2019 23:43:59 +0900 (JST)
Subject: [ruby-changes:57990] a2c26fe1c6 (master): Fix fallback in URI.encode_www_form_component to include #
https://git.ruby-lang.org/ruby.git/commit/?id=a2c26fe1c6 From a2c26fe1c6d49b54494b7c6301cc4c77596eec0c Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Thu, 20 Jun 2019 14:47:15 -0700 Subject: Fix fallback in URI.encode_www_form_component to include # Patch from Matthew Kerwin. Fixes [Bug #14358] diff --git a/lib/uri/common.rb b/lib/uri/common.rb index 17d9ffc..811ec98 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -370,7 +370,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/common.rb#L370 if str.encoding != Encoding::ASCII_8BIT if enc && enc != Encoding::ASCII_8BIT str.encode!(Encoding::UTF_8, invalid: :replace, undef: :replace) - str.encode!(enc, fallback: ->(x){"&#{x.ord};"}) + str.encode!(enc, fallback: ->(x){"&##{x.ord};"}) end str.force_encoding(Encoding::ASCII_8BIT) end diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index 5bec21c..1afa35f 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -82,6 +82,8 @@ class TestCommon < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/uri/test_common.rb#L82 "\u3042".encode("sjis"), Encoding::UTF_8)) assert_equal("B0", URI.encode_www_form_component( "\u3042".encode("sjis"), Encoding::UTF_16LE)) + assert_equal("%26%23730%3B", URI.encode_www_form_component( + "\u02DA", Encoding::WINDOWS_1252)) # invalid assert_equal("%EF%BF%BD%EF%BF%BD", URI.encode_www_form_component( -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/