Bug #16922

single quote should be escaped in xml

Added by lisbethw1130 (Lisbeth Wu) 2 months ago. Updated 24 days ago.

Target version:
ruby -v:
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]


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:

and I found a more clean table in sitemap spec:

Ampersand   &   &
Single Quote    '   '
Double Quote    "   "
Greater Than    >   >
Less Than   <   &lt;

expected output:

puts ':$+,;:=?@&\'"><'.encode(xml: :attr)

":$+,;:=?@&amp; **&apos;** &quot;&gt;&lt;"

real output:

":$+,;:=?@&amp; **'** &quot;&gt;&lt;"

Thanks for helping


Updated by shyouhei (Shyouhei Urabe) 2 months ago

  • Description updated (diff)

Updated by jeremyevans0 (Jeremy Evans) 2 months ago

  • Assignee set to akr (Akira Tanaka)

I've added a pull request to escape ' as &apos;:

akr (Akira Tanaka), can you let me know if this is correct?

Updated by lisbethw1130 (Lisbeth Wu) 27 days ago

any update about this issue?

Updated by jeremyevans0 (Jeremy Evans) 27 days ago

Well, I haven't heard from @akr. But if he doesn't respond in the next few days, I'll merge my pull request.


Updated by jeremyevans (Jeremy Evans) 24 days ago

  • Status changed from Open to Closed

Applied in changeset git|ddd9704ae9bf884d867b6f57a16c095a79393fff.

Encode ' as ' when using encode(xml: :attr)

Fixes [Bug #16922]

Also available in: Atom PDF