[ruby-trunk - Bug #5913][Assigned] CGI.escape cannot escape a string with invalid byte sequence

Issue #5913 has been reported by Kenta M…


Bug #5913: CGI.escape cannot escape a string with invalid byte sequence.
https://bugs.ruby-lang.org/issues/5913

Author: Kenta M.
Status: Assigned
Priority: Normal
Assignee: Takeyuki F.
Category: lib
Target version: 2.0.0
ruby -v: ruby 2.0.0dev (2012-01-20 trunk 34342) [x86_64-darwin11.2.0]

不正なバイト列を持つ文字列を CGI.escape に渡すと ArgumentError が起きます。

$ .prefix/bin/ruby -rcgi -ve ‘p
CGI.escape("\xC0<<".force_encoding(“UTF-8”))’
ruby 2.0.0dev (2012-01-20 trunk 34342) [x86_64-darwin11.2.0]
/Users/kenta-murata/work/ruby.git/.prefix/lib/ruby/2.0.0/cgi/util.rb:7:in
gsub': invalid byte sequence in UTF-8 (ArgumentError) from /Users/kenta-murata/work/ruby.git/.prefix/lib/ruby/2.0.0/cgi/util.rb:7:inescape’
from -e:1:in `’

この振舞いがバグなら、このパッチで修正可能です https://gist.github.com/1646048

Issue #5913 has been updated by Yui NARUSE.

バグじゃないかと思います。

パッチについては、String#valid_encoding? は文字列スキャンが走るので、
常時 ASCII-8BIT を設定して戻したほうがいいんじゃないかと思います。

Bug #5913: CGI.escape cannot escape a string with invalid byte sequence.
https://bugs.ruby-lang.org/issues/5913

Author: Kenta M.
Status: Assigned
Priority: Normal
Assignee: Takeyuki F.
Category: lib
Target version: 2.0.0
ruby -v: ruby 2.0.0dev (2012-01-20 trunk 34342) [x86_64-darwin11.2.0]

不正なバイト列を持つ文字列を CGI.escape に渡すと ArgumentError が起きます。

$ .prefix/bin/ruby -rcgi -ve ‘p
CGI.escape("\xC0<<".force_encoding(“UTF-8”))’
ruby 2.0.0dev (2012-01-20 trunk 34342) [x86_64-darwin11.2.0]
/Users/kenta-murata/work/ruby.git/.prefix/lib/ruby/2.0.0/cgi/util.rb:7:in
gsub': invalid byte sequence in UTF-8 (ArgumentError) from /Users/kenta-murata/work/ruby.git/.prefix/lib/ruby/2.0.0/cgi/util.rb:7:inescape’
from -e:1:in `’

この振舞いがバグなら、このパッチで修正可能です https://gist.github.com/1646048

Issue #5913 has been updated by Kenta M…

新しいパッチを作りました。
https://gist.github.com/1646162

これで問題なければ、コミットします。良いですか?

Bug #5913: CGI.escape cannot escape a string with invalid byte sequence.
https://bugs.ruby-lang.org/issues/5913

Author: Kenta M.
Status: Assigned
Priority: Normal
Assignee: Takeyuki F.
Category: lib
Target version: 2.0.0
ruby -v: ruby 2.0.0dev (2012-01-20 trunk 34342) [x86_64-darwin11.2.0]

不正なバイト列を持つ文字列を CGI.escape に渡すと ArgumentError が起きます。

$ .prefix/bin/ruby -rcgi -ve ‘p
CGI.escape("\xC0<<".force_encoding(“UTF-8”))’
ruby 2.0.0dev (2012-01-20 trunk 34342) [x86_64-darwin11.2.0]
/Users/kenta-murata/work/ruby.git/.prefix/lib/ruby/2.0.0/cgi/util.rb:7:in
gsub': invalid byte sequence in UTF-8 (ArgumentError) from /Users/kenta-murata/work/ruby.git/.prefix/lib/ruby/2.0.0/cgi/util.rb:7:inescape’
from -e:1:in `’

この振舞いがバグなら、このパッチで修正可能です https://gist.github.com/1646048

Issue #5913 has been updated by Kenta M…

Status changed from Assigned to Closed
Assignee changed from Takeyuki F. to Kenta M.

r34346 で修正しました。

Bug #5913: CGI.escape cannot escape a string with invalid byte sequence.
https://bugs.ruby-lang.org/issues/5913

Author: Kenta M.
Status: Closed
Priority: Normal
Assignee: Kenta M.
Category: lib
Target version: 2.0.0
ruby -v: ruby 2.0.0dev (2012-01-20 trunk 34342) [x86_64-darwin11.2.0]

不正なバイト列を持つ文字列を CGI.escape に渡すと ArgumentError が起きます。

$ .prefix/bin/ruby -rcgi -ve ‘p
CGI.escape("\xC0<<".force_encoding(“UTF-8”))’
ruby 2.0.0dev (2012-01-20 trunk 34342) [x86_64-darwin11.2.0]
/Users/kenta-murata/work/ruby.git/.prefix/lib/ruby/2.0.0/cgi/util.rb:7:in
gsub': invalid byte sequence in UTF-8 (ArgumentError) from /Users/kenta-murata/work/ruby.git/.prefix/lib/ruby/2.0.0/cgi/util.rb:7:inescape’
from -e:1:in `’

この振舞いがバグなら、このパッチで修正可能です https://gist.github.com/1646048

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs