Issue #13178 has been updated by Nobuyoshi Nakada.

Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.1: REQUIRED, 2.2: REQUIRED, 2.3: REQUIRED

It's an older bug than it.

```
$ ruby2.1 -rcgi -e 'CGI.accept_charset = "ISO-8859-15"; p CGI.unescape("foo").encoding'
#<Encoding:UTF-8>
```

There are different `@@accept_charset` variables.

----------------------------------------
Bug #13178: CGI.unescape change in behavior
https://bugs.ruby-lang.org/issues/13178#change-62813

* Author: Vit Ondruch
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]
* Backport: 2.1: REQUIRED, 2.2: REQUIRED, 2.3: REQUIRED
----------------------------------------
CGI.unescape does not work anymore when just "cgi/util" is required.

~~~
$ ruby -v -rcgi/util -e 'CGI.unescape("foo=bar&foo=baz&page=1")'
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]

$ ruby -v -rcgi/util -e 'CGI.unescape("foo=bar&foo=baz&page=1")'
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]
-e:1:in `unescape': uninitialized class variable @@accept_charset in #<Class:CGI> (NameError)
	from -e:1:in `<main>'
~~~

It works just fine if whole "cgi" is required. Not sure if this is intentional or just side effect (probably due to r55540 or r54655 ?), but it breaks existing projects, e.g. httparty test suite fails due to this change:

~~~
  1) HTTParty::Request::NON_RAILS_QUERY_STRING_NORMALIZER doesn't modify strings
     Failure/Error: expect(CGI.unescape(query_string)).to eq("foo=bar&foo=baz")
     NameError:
       uninitialized class variable @@accept_charset in #<Class:CGI>
     # ./spec/httparty/request_spec.rb:13:in `unescape'
     # ./spec/httparty/request_spec.rb:13:in `block (3 levels) in <top (required)>'
~~~

Also please note that httparty does not require "cqi" at all. It is required via some transitive dependencies. Presumably via ERB [1]. So in case that this is intentional behavior, ERB should require s|cgi/utils|cgi| IMO.


[1]: https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L15



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>