Skip to content

Commit ddd9704

Browse files
committed
Encode ' as ' when using encode(xml: :attr)
Fixes [Bug #16922]
1 parent 82489f0 commit ddd9704

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

enc/trans/escape.trans

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
], nil)
1919

2020
transcode_tblgen("", "xml_attr_content_escape", [
21-
["{00-21,23-25,27-3B,3D,3F-FF}", :nomap],
21+
["{00-21,23-25,28-3B,3D,3F-FF}", :nomap],
2222
["22", hexstr(""")],
2323
["26", hexstr("&")],
24+
["27", hexstr("'")],
2425
["3C", hexstr("<")],
2526
["3E", hexstr(">")]
2627
], nil)

test/ruby/test_econv.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ def test_xml_escape_attr_content
803803
assert_equal('', ec.finish)
804804

805805
ec = Encoding::Converter.new("", "xml_attr_content_escape")
806-
assert_equal('&amp;&lt;&gt;&quot;', ec.convert("&<>\""))
806+
assert_equal('&amp;&lt;&gt;&quot;&apos;', ec.convert("&<>\"'"))
807807
assert_equal('', ec.finish)
808808
end
809809

@@ -844,7 +844,7 @@ def test_xml_escape_with_charref
844844
def test_xml_hasharg
845845
assert_equal("&amp;\e$B$&\e(B&#x2665;&amp;\"'".force_encoding("iso-2022-jp"),
846846
"&\u3046\u2665&\"'".encode("iso-2022-jp", xml: :text))
847-
assert_equal("\"&amp;\e$B$&\e(B&#x2661;&amp;&quot;'\"".force_encoding("iso-2022-jp"),
847+
assert_equal("\"&amp;\e$B$&\e(B&#x2661;&amp;&quot;&apos;\"".force_encoding("iso-2022-jp"),
848848
"&\u3046\u2661&\"'".encode("iso-2022-jp", xml: :attr))
849849

850850
assert_equal("&amp;\u3046\u2661&amp;\"'".force_encoding("utf-8"),

test/ruby/test_io_m17n.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -2047,19 +2047,19 @@ def test_w_xml_attr
20472047
with_tmpdir {
20482048
open("raw.txt", "wb", xml: :attr) {|f| f.print '&<>"\''; f.puts "\u4E02\u3042" }
20492049
content = File.read("raw.txt", :mode=>"rb:ascii-8bit")
2050-
assert_equal("\"&amp;&lt;&gt;&quot;'\u4E02\u3042\n\"".force_encoding("ascii-8bit"), content)
2050+
assert_equal("\"&amp;&lt;&gt;&quot;&apos;\u4E02\u3042\n\"".force_encoding("ascii-8bit"), content)
20512051

20522052
open("ascii.txt", "wb:us-ascii", xml: :attr) {|f| f.print '&<>"\''; f.puts "\u4E02\u3042" }
20532053
content = File.read("ascii.txt", :mode=>"rb:ascii-8bit")
2054-
assert_equal("\"&amp;&lt;&gt;&quot;'&#x4E02;&#x3042;\n\"".force_encoding("ascii-8bit"), content)
2054+
assert_equal("\"&amp;&lt;&gt;&quot;&apos;&#x4E02;&#x3042;\n\"".force_encoding("ascii-8bit"), content)
20552055

20562056
open("iso-2022-jp.txt", "wb:iso-2022-jp", xml: :attr) {|f| f.print '&<>"\''; f.puts "\u4E02\u3042" }
20572057
content = File.read("iso-2022-jp.txt", :mode=>"rb:ascii-8bit")
2058-
assert_equal("\"&amp;&lt;&gt;&quot;'&#x4E02;\e$B$\"\e(B\n\"".force_encoding("ascii-8bit"), content)
2058+
assert_equal("\"&amp;&lt;&gt;&quot;&apos;&#x4E02;\e$B$\"\e(B\n\"".force_encoding("ascii-8bit"), content)
20592059

20602060
open("utf-16be.txt", "wb:utf-16be", xml: :attr) {|f| f.print '&<>"\''; f.puts "\u4E02\u3042" }
20612061
content = File.read("utf-16be.txt", :mode=>"rb:ascii-8bit")
2062-
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)
2062+
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)
20632063

20642064
open("eucjp.txt", "w:euc-jp:utf-8", xml: :attr) {|f|
20652065
f.print "\u4E02" # U+4E02 is 0x3021 in JIS X 0212

0 commit comments

Comments
 (0)