ruby-changes:62182
From: Jeremy <ko1@a...>
Date: Sat, 11 Jul 2020 01:34:27 +0900 (JST)
Subject: [ruby-changes:62182] ddd9704ae9 (master): Encode ' as ' when using encode(xml: :attr)
https://git.ruby-lang.org/ruby.git/commit/?id=ddd9704ae9 From ddd9704ae9bf884d867b6f57a16c095a79393fff Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Tue, 2 Jun 2020 10:35:00 -0700 Subject: Encode ' as ' when using encode(xml: :attr) Fixes [Bug #16922] diff --git a/enc/trans/escape.trans b/enc/trans/escape.trans index c76ffa0..36d9dd0 100644 --- a/enc/trans/escape.trans +++ b/enc/trans/escape.trans @@ -18,9 +18,10 @@ https://github.com/ruby/ruby/blob/trunk/enc/trans/escape.trans#L18 ], nil) transcode_tblgen("", "xml_attr_content_escape", [ - ["{00-21,23-25,27-3B,3D,3F-FF}", :nomap], + ["{00-21,23-25,28-3B,3D,3F-FF}", :nomap], ["22", hexstr(""")], ["26", hexstr("&")], + ["27", hexstr("'")], ["3C", hexstr("<")], ["3E", hexstr(">")] ], nil) diff --git a/test/ruby/test_econv.rb b/test/ruby/test_econv.rb index 5a4af9b..a1ab1c8 100644 --- a/test/ruby/test_econv.rb +++ b/test/ruby/test_econv.rb @@ -803,7 +803,7 @@ class TestEncodingConverter < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_econv.rb#L803 assert_equal('', ec.finish) ec = Encoding::Converter.new("", "xml_attr_content_escape") - assert_equal('&<>"', ec.convert("&<>\"")) + assert_equal('&<>"'', ec.convert("&<>\"'")) assert_equal('', ec.finish) end @@ -844,7 +844,7 @@ class TestEncodingConverter < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_econv.rb#L844 def test_xml_hasharg assert_equal("&\e$B$&\e(B♥&\"'".force_encoding("iso-2022-jp"), "&\u3046\u2665&\"'".encode("iso-2022-jp", xml: :text)) - assert_equal("\"&\e$B$&\e(B♡&"'\"".force_encoding("iso-2022-jp"), + assert_equal("\"&\e$B$&\e(B♡&"'\"".force_encoding("iso-2022-jp"), "&\u3046\u2661&\"'".encode("iso-2022-jp", xml: :attr)) assert_equal("&\u3046\u2661&\"'".force_encoding("utf-8"), diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb index e5b0ef0..7b37893 100644 --- a/test/ruby/test_io_m17n.rb +++ b/test/ruby/test_io_m17n.rb @@ -2047,19 +2047,19 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io_m17n.rb#L2047 with_tmpdir { open("raw.txt", "wb", xml: :attr) {|f| f.print '&<>"\''; f.puts "\u4E02\u3042" } content = File.read("raw.txt", :mode=>"rb:ascii-8bit") - assert_equal("\"&<>"'\u4E02\u3042\n\"".force_encoding("ascii-8bit"), content) + assert_equal("\"&<>"'\u4E02\u3042\n\"".force_encoding("ascii-8bit"), content) open("ascii.txt", "wb:us-ascii", xml: :attr) {|f| f.print '&<>"\''; f.puts "\u4E02\u3042" } content = File.read("ascii.txt", :mode=>"rb:ascii-8bit") - assert_equal("\"&<>"'丂あ\n\"".force_encoding("ascii-8bit"), content) + assert_equal("\"&<>"'丂あ\n\"".force_encoding("ascii-8bit"), content) open("iso-2022-jp.txt", "wb:iso-2022-jp", xml: :attr) {|f| f.print '&<>"\''; f.puts "\u4E02\u3042" } content = File.read("iso-2022-jp.txt", :mode=>"rb:ascii-8bit") - assert_equal("\"&<>"'丂\e$B$\"\e(B\n\"".force_encoding("ascii-8bit"), content) + assert_equal("\"&<>"'丂\e$B$\"\e(B\n\"".force_encoding("ascii-8bit"), content) open("utf-16be.txt", "wb:utf-16be", xml: :attr) {|f| f.print '&<>"\''; f.puts "\u4E02\u3042" } content = File.read("utf-16be.txt", :mode=>"rb:ascii-8bit") - assert_equal("\0\"\0&\0a\0m\0p\0;\0&\0l\0t\0;\0&\0g\0t\0;\0&\0q\0u\0o\0t\0;\0'\x4E\x02\x30\x42\0\n\0\"".force_encoding("ascii-8bit"), content) + assert_equal("\0\"\0&\0a\0m\0p\0;\0&\0l\0t\0;\0&\0g\0t\0;\0&\0q\0u\0o\0t\0;\0&\0a\0p\0o\0s\0;\x4E\x02\x30\x42\0\n\0\"".force_encoding("ascii-8bit"), content) open("eucjp.txt", "w:euc-jp:utf-8", xml: :attr) {|f| f.print "\u4E02" # U+4E02 is 0x3021 in JIS X 0212 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/