From: me@... Date: 2018-05-03T00:22:02+00:00 Subject: [ruby-core:86852] [Ruby trunk Bug#14732] CGI.unescape returns different instance between Ruby 2.3 and 2.4 Issue #14732 has been updated by jnchito (Junichi Ito). normalperson (Eric Wong) wrote: > > > https://bugs.ruby-lang.org/issues/14732 > > r63328 This also affects 2.3 for unescapeHTML. I confirmed r63328, but could not understand the valid specification. In Ruby 2.3, CGI.escape and CGI.unescape always return String instance regardless of class and value: ~~~ text $ ruby -v -rcgi/util -e 'class S < String; end; puts CGI.escape(S.new("a")).class' ruby 2.3.6p384 (2017-12-14 revision 61254) [x86_64-darwin17] String $ ruby -v -rcgi/util -e 'class S < String; end; puts CGI.escape(S.new(">")).class' ruby 2.3.6p384 (2017-12-14 revision 61254) [x86_64-darwin17] String $ ruby -v -rcgi/util -e 'class S < String; end; puts CGI.unescape(S.new("a")).class' ruby 2.3.6p384 (2017-12-14 revision 61254) [x86_64-darwin17] String $ ruby -v -rcgi/util -e 'class S < String; end; puts CGI.unescape(S.new("%3E")).class' ruby 2.3.6p384 (2017-12-14 revision 61254) [x86_64-darwin17] String ~~~ In Ruby 2.4, results differ according to argument values: ~~~ text $ ruby -v -rcgi/util -e 'class S < String; end; puts CGI.escape(S.new("a")).class' ruby 2.4.4p296 (2018-03-28 revision 63013) [x86_64-darwin17] S $ ruby -v -rcgi/util -e 'class S < String; end; puts CGI.escape(S.new(">")).class' ruby 2.4.4p296 (2018-03-28 revision 63013) [x86_64-darwin17] String $ ruby -v -rcgi/util -e 'class S < String; end; puts CGI.unescape(S.new("a")).class' ruby 2.4.4p296 (2018-03-28 revision 63013) [x86_64-darwin17] S $ ruby -v -rcgi/util -e 'class S < String; end; puts CGI.unescape(S.new("%3E")).class' ruby 2.4.4p296 (2018-03-28 revision 63013) [x86_64-darwin17] String ~~~ With r63328, I feel the all results would be the instance of "S" and this behavior is different from Ruby 2.3. But is this valid in Ruby 2.4? ---------------------------------------- Bug #14732: CGI.unescape returns different instance between Ruby 2.3 and 2.4 https://bugs.ruby-lang.org/issues/14732#change-71818 * Author: jnchito (Junichi Ito) * Status: Closed * Priority: Normal * Assignee: * Target version: * ruby -v: 2.4.4 * Backport: 2.3: REQUIRED, 2.4: REQUIRED, 2.5: REQUIRED ---------------------------------------- In Ruby 2.3, CGI.unescape always returns String object: ~~~ ruby $ ruby -v -rcgi/util -e 'class S < String; end; puts CGI.unescape(S.new("a")).class' ruby 2.3.6p384 (2017-12-14 revision 61254) [x86_64-darwin17] String ~~~ But in Ruby 2.4, it might return non-String object when the argument value is not a String instance: ~~~ ruby $ ruby -v -rcgi/util -e 'class S < String; end; puts CGI.unescape(S.new("a")).class' ruby 2.4.4p296 (2018-03-28 revision 63013) [x86_64-darwin17] S ~~~ This change triggered the following issue: https://github.com/rest-client/rest-client/issues/662 Is this change intentional? -- https://bugs.ruby-lang.org/ Unsubscribe: