-
Notifications
You must be signed in to change notification settings - Fork 57
Description
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>&"<>'</specialChars>
When executed on Ruby 2.0.0, it produces this output:
Ruby Version: 2.0.0
<specialChars>&"<>'</specialChars>
The apostrophe character is not encoded at all on Ruby 1.9.3, but on ruby 2.0 it is converted to '. 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: <>&"'
but this output on Ruby 2.0:
Ruby Version: 2.1.1
Original: <>&"'
Encoded: <>&"'
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 ' instead of '. In fact, encoding it as ' is directly causing me a problem here. :)