Skip to content

encoding of special characters is not consistent across ruby versions #41

@kashook

Description

@kashook

Consider the following ruby script:

require 'gyoku'
puts "Ruby Version: #{RUBY_VERSION}"
puts Gyoku.xml(:special_chars => %q{&"<>'})

When executed on Ruby 1.9.3, it produces this output:

Ruby Version: 1.9.3
<specialChars>&amp;&quot;&lt;&gt;'</specialChars>

When executed on Ruby 2.0.0, it produces this output:

Ruby Version: 2.0.0
<specialChars>&amp;&quot;&lt;&gt;&#39;</specialChars>

The apostrophe character is not encoded at all on Ruby 1.9.3, but on ruby 2.0 it is converted to &#39;. The reason appears to be because of this line. The behavior of the CGI.escapeHTML function seems to have changed from Ruby 1.9.3 to Ruby 2.0. Here is an example.

This script:

require 'cgi'
string = %q{<>&"'}
puts "Ruby Version: #{RUBY_VERSION}"
puts "Original: #{string}"
puts "Encoded: #{CGI.escapeHTML(string)}"

produces this output on Ruby 1.9.3:

Ruby Version: 1.9.3
Original: <>&"'
Encoded: &lt;&gt;&amp;&quot;'

but this output on Ruby 2.0:

Ruby Version: 2.1.1
Original: <>&"'
Encoded: &lt;&gt;&amp;&quot;&#39;

It seems like the output should not change depending on the ruby version. In addition, if an apostrophe is going to be encoded, it seems like it would be more correct to encode it as &apos; instead of &#39;. In fact, encoding it as &#39; is directly causing me a problem here. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions