Bug #16922
closedsingle quote should be escaped in xml
Description
This is Lisbeth from Taiwan. I'm trying to convert a string to xml by using 'string'.encode(xml: :attr) but single quote doesn't escape as expected
Here's the spec shows which character needs to be escaped: https://www.w3.org/TR/xml/#dt-escape
and I found a more clean table in sitemap spec: https://www.sitemaps.org/protocol.html#escaping
Ampersand & &
Single Quote ' '
Double Quote " "
Greater Than > >
Less Than < <
expected output:
puts ':$+,;:=?@&'"><'.encode(xml: :attr)
":$+,;:=?@& **'** "><"
real output:
":$+,;:=?@& **'** "><"
Thanks for helping
Updated by shyouhei (Shyouhei Urabe) over 4 years ago
- Description updated (diff)
Updated by jeremyevans0 (Jeremy Evans) over 4 years ago
- Assignee set to akr (Akira Tanaka)
I've added a pull request to escape '
as '
: https://github.com/ruby/ruby/pull/3177
@akr (Akira Tanaka), can you let me know if this is correct?
Updated by lisbethw1130 (Lisbeth Wu) over 4 years ago
any update about this issue?
Updated by jeremyevans0 (Jeremy Evans) over 4 years ago
Well, I haven't heard from @akr (Akira Tanaka). But if he doesn't respond in the next few days, I'll merge my pull request.
Updated by jeremyevans (Jeremy Evans) over 4 years ago
- Status changed from Open to Closed
Applied in changeset git|ddd9704ae9bf884d867b6f57a16c095a79393fff.
Encode ' as ' when using encode(xml: :attr)
Fixes [Bug #16922]
Updated by headius (Charles Nutter) over 2 years ago
- Backport changed from 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN to 2.5: UNKNOWN, 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED
Requesting backport to 2.6. JRuby runs the CRuby test suite and wants to fix the same issue, but the existing tests in ruby_2_6 branch fail.
Updated by headius (Charles Nutter) over 2 years ago
See https://github.com/jruby/jruby/pull/7142 for JRuby update of our jcodings encoding backend, plus the test changes from https://github.com/ruby/ruby/pull/3177.
Updated by nagachika (Tomoyuki Chikanaga) over 2 years ago
- Backport changed from 2.5: UNKNOWN, 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED to 2.6: REQUIRED, 2.7: REQUIRED, 3.0: DONTNEED
ruby_3_0 branch includes the changeset git|ddd9704ae9bf884d867b6f57a16c095a79393fff.