# Bug in REXML escape codes

**URL:** <https://rubytalk.org/t/bug-in-rexml-escape-codes/22044>\
**Category:** ruby-talk\
**Created:** [31 October 2005 17:02 UTC](https://rubytalk.org/t/bug-in-rexml-escape-codes/22044 "2005-10-31T17:02:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phlip1](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@Phlip1](https://rubytalk.org/u/Phlip1)\
**Post date:** [31 October 2005 17:02 UTC](https://rubytalk.org/t/bug-in-rexml-escape-codes/22044/1 "2005-10-31T17:02:07Z")

</div>

Rubies:

REXML can't escape & properly:

&nbsp;&nbsp;&nbsp;&nbsp;require 'test/unit'  
&nbsp;&nbsp;&nbsp;&nbsp;require 'rexml/document'  
&nbsp;&nbsp;&nbsp;&nbsp;include REXML

&nbsp;&nbsp;&nbsp;&nbsp;class RexmlIssue \< Test::Unit::TestCase  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def test\_transmitHTMLescapes()  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doc = Document.new('\<zone/\>')  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;zone = XPath.first(doc, '/zone')  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;zone.text = '\< \> &gt;'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File.open('sample.xml', 'w') {|fh| doc.write(fh) }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sample = File.read('sample.xml')  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assert\_equal '\<zone\>&lt; &gt; &amp;gt;\</zone\>', sample  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;end

When I feed REXML &gt; in clear text, it does not expand that into  
&amp;gt;.

So when we read zone.text back, we get '\< \> \>', not '\< \> &gt;' again.

I have a patch in my code - I just call a generic escapeHTML() before  
stuffing the node's text. But naturally a real fix would be welcome.

> **···**
>
> --  
> &nbsp;&nbsp;Phlip  
> &nbsp;&nbsp;[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand)

---

<div class="post-metadata">

**Author:** ![daz](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@daz](https://rubytalk.org/u/daz)\
**Post date:** [1 November 2005 10:17 UTC](https://rubytalk.org/t/bug-in-rexml-escape-codes/22044/2 "2005-11-01T10:17:08Z")

</div>

Phlip wrote:

> Rubies:
> 
> REXML can't escape & properly:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;require 'test/unit'  
> &nbsp;&nbsp;&nbsp;&nbsp;require 'rexml/document'  
> &nbsp;&nbsp;&nbsp;&nbsp;include REXML
> 
> &nbsp;&nbsp;&nbsp;&nbsp;class RexmlIssue \< Test::Unit::TestCase  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def test\_transmitHTMLescapes()  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doc = Document.new('\<zone/\>')  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;zone = XPath.first(doc, '/zone')  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;zone.text = '\< \> &gt;'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File.open('sample.xml', 'w') {|fh| doc.write(fh) }  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sample = File.read('sample.xml')  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assert\_equal '\<zone\>&lt; &gt; &amp;gt;\</zone\>', sample  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;&nbsp;&nbsp;end
> 
> When I feed REXML &gt; in clear text, it does not expand that into  
> &amp;gt;.
> 
> So when we read zone.text back, we get '\< \> \>', not '\< \> &gt;' again.
> 
> I have a patch in my code - I just call a generic escapeHTML() before  
> stuffing the node's text. But naturally a real fix would be welcome.

This is so like a thread from 11 days ago:

[qurl.net&nbsp;-&nbsp;This website is for sale!&nbsp;-&nbsp;qurl Resources and Information.](http://qurl.net/mz) (quod vide)

daz
