bug in REXML escape codes

Discussion in 'Ruby' started by Phlip, Oct 31, 2005.

  1. Phlip

    Phlip Guest

    Rubies:

    REXML can't escape & properly:

    require 'test/unit'
    require 'rexml/document'
    include REXML

    class RexmlIssue < Test::Unit::TestCase
    def test_transmitHTMLescapes()
    doc = Document.new('<zone/>')
    zone = XPath.first(doc, '/zone')
    zone.text = '< > &gt;'
    File.open('sample.xml', 'w') {|fh| doc.write(fh) }
    sample = File.read('sample.xml')
    assert_equal '<zone>&lt; &gt; &amp;gt;</zone>', sample
    end
    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.

    --
    Phlip
    http://c2.com/cgi/wiki?ZeekLand
    Phlip, Oct 31, 2005
    #1
    1. Advertising

  2. Phlip

    daz Guest

    Phlip wrote:
    > Rubies:
    >
    > REXML can't escape & properly:
    >
    > require 'test/unit'
    > require 'rexml/document'
    > include REXML
    >
    > class RexmlIssue < Test::Unit::TestCase
    > def test_transmitHTMLescapes()
    > doc = Document.new('<zone/>')
    > zone = XPath.first(doc, '/zone')
    > zone.text = '< > &gt;'
    > File.open('sample.xml', 'w') {|fh| doc.write(fh) }
    > sample = File.read('sample.xml')
    > assert_equal '<zone>&lt; &gt; &amp;gt;</zone>', sample
    > end
    > 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:

    http://qurl.net/mz (quod vide)


    daz
    daz, Nov 1, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    2,797
    Malcolm
    Aug 20, 2005
  2. slomo
    Replies:
    5
    Views:
    1,506
    Duncan Booth
    Dec 2, 2007
  3. Damphyr
    Replies:
    2
    Views:
    131
    Damphyr
    Jul 16, 2003
  4. Daniel Berger

    rexml error - REXML::Validation

    Daniel Berger, Oct 12, 2004, in forum: Ruby
    Replies:
    2
    Views:
    144
    Henrik Horneber
    Oct 12, 2004
  5. Phlip
    Replies:
    0
    Views:
    135
    Phlip
    Jan 15, 2008
Loading...

Share This Page