ruby/lib
David Rodríguez e7518a7859 Validate user input encoding
If the user has the encoding of her system messed up, she may end up
sending us incorrectly encoding input, causing "invalid byte sequence in
UTF-8" errors at random places.

These errors can be forced on a system without encoding issues with
something like:

```
$ gem install$(echo -e "\xFF") foo
/Users/deivid/.asdf/installs/ruby/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/config_file.rb:534:in `block in set_config_file_name': invalid byte sequence in UTF-8 (ArgumentError)
	from /Users/deivid/.asdf/installs/ruby/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/config_file.rb:530:in `each'
	from /Users/deivid/.asdf/installs/ruby/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/config_file.rb:530:in `set_config_file_name'
	from /Users/deivid/.asdf/installs/ruby/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/config_file.rb:177:in `initialize'
	from /Users/deivid/.asdf/installs/ruby/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/gem_runner.rb:71:in `new'
	from /Users/deivid/.asdf/installs/ruby/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/gem_runner.rb:71:in `do_configuration'
	from /Users/deivid/.asdf/installs/ruby/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/gem_runner.rb:33:in `run'
	from /Users/deivid/.asdf/installs/ruby/3.2.1/bin/gem:10:in `<main>'
```

This commit makes RubyGems print a better error in this case:

```
$ ruby -Ilib bin/gem install$(echo -e "\xFF") foo
/Users/deivid/Code/rubygems/rubygems/lib/rubygems/gem_runner.rb:75:in `validate_encoding': invalid argument: 'install�' has invalid encoding (Gem::OptionParser::InvalidArgument)
	from /Users/deivid/Code/rubygems/rubygems/lib/rubygems/gem_runner.rb:31:in `run'
	from bin/gem:10:in `<main>'
```
2024-11-04 10:18:55 +00:00
..
bundler [rubygems/rubygems] Fix incompatible encodings error 2024-11-04 10:04:40 +00:00
cgi
did_you_mean [ruby/did_you_mean] Move development dependencies to Gemfile 2024-05-05 23:22:28 +00:00
erb [ruby/erb] Version 4.0.4 2024-01-04 22:34:59 +00:00
error_highlight [ruby/error_highlight] Rename the ErrorHighlight::DefaultFormatter setting to max_snippet_width for clarity 2024-10-24 00:29:20 +00:00
forwardable
irb [ruby/irb] Always use alternate sceen on alt-d 2024-10-18 17:15:11 +00:00
json/ext/generator [ruby/json] Move State#configure back into C 2024-11-01 13:04:24 +09:00
logger [ruby/logger] Bump up 1.6.1 2024-09-02 02:29:24 +00:00
net [ruby/net-http] implement talking SSL to the proxy too 2024-07-11 01:56:08 +00:00
open3 [ruby/open3] Bump up v0.2.1 2023-12-16 11:48:49 +08:00
optparse [ruby/optparse] Fix typo [ci skip] 2024-04-18 10:27:19 +09:00
prism [ruby/prism] Relocation 2024-10-16 15:56:01 +00:00
random [ruby/securerandom] Update UUID documentation with RFC9562 links 2024-06-20 08:34:31 +00:00
rdoc [ruby/rdoc] Use thicker fonts with high contrast to improve 2024-10-31 10:05:19 +00:00
reline [ruby/reline] nonprinting_start and nonprinting_end should be 2024-10-24 16:36:39 +00:00
ruby_vm/rjit Optimized instruction for Hash#freeze 2024-09-05 12:46:02 +02:00
rubygems Validate user input encoding 2024-11-04 10:18:55 +00:00
set [ruby/set] Drop support for Ruby 2 2023-12-23 16:50:29 +09:00
syntax_suggest [ruby/syntax_suggest] Bump up 2.0.1 2024-10-18 02:07:02 +00:00
unicode_normalize
uri [ruby/uri] Fix spelling of "cannot" 2024-09-17 22:12:12 +00:00
yaml [ruby/yaml] Support old version of Psych 2024-10-16 08:49:54 +00:00
benchmark.gemspec [ruby/benchmark] Set required_ruby_version = ">= 2.1.0" 2024-09-08 16:43:50 +00:00
benchmark.rb [ruby/benchmark] Add example for Benchmark.realtime 2024-09-27 04:31:47 +00:00
bundled_gems.rb Don't warn the bundled gems that are migrated at Ruby 3.0. 2024-09-30 18:53:21 +09:00
bundler.rb [rubygems/rubygems] Consistently use :create action when creating directories 2024-10-23 08:53:18 +00:00
cgi.rb
delegate.gemspec
delegate.rb Do not include a backtick in error messages and backtraces 2024-02-15 18:42:31 +09:00
did_you_mean.rb
English.gemspec
English.rb
erb.gemspec
erb.rb
error_highlight.rb
fileutils.gemspec [ruby/fileutils] Update license files same as ruby/ruby 2024-08-27 00:39:24 +00:00
fileutils.rb [ruby/fileutils] Bump up v1.7.3 2024-11-01 05:04:32 +00:00
find.gemspec [ruby/find] find.gemspec: Drop executables dir config 2024-05-17 02:05:31 +00:00
find.rb
forwardable.rb
ipaddr.gemspec [ruby/ipaddr] Drop support for Ruby 2.3 2024-10-23 04:07:30 +00:00
ipaddr.rb [ruby/ipaddr] Bump the version to 1.2.7 2024-10-19 12:59:03 +00:00
irb.rb [ruby/irb] Suppress "literal string will be frozen in the future" 2024-10-18 17:15:25 +00:00
logger.rb [ruby/logger] Guarantee level_override exists 2024-08-21 01:10:56 +00:00
mkmf.rb Remove leading spaces from LIBPATHFLAG and RPATHFLAG 2024-09-29 23:07:16 +09:00
open-uri.gemspec
open-uri.rb [ruby/open-uri] Update error message for request_specific_fields option validation 2024-09-08 14:13:00 +00:00
open3.rb
optionparser.rb
optparse.rb [ruby/optparse] Prefer require_relative 2024-09-03 04:43:25 +00:00
ostruct.gemspec
ostruct.rb Do not include a backtick in error messages and backtraces 2024-02-15 18:42:31 +09:00
pp.gemspec
pp.rb prettyprint hash with colon style 2024-10-03 18:47:09 +09:00
prettyprint.gemspec
prettyprint.rb
prism.rb [ruby/prism] Relocation 2024-10-16 15:56:01 +00:00
pstore.gemspec
pstore.rb Do not include a backtick in error messages and backtraces 2024-02-15 18:42:31 +09:00
rdoc.rb [ruby/rdoc] [DOC] Fix links (https://github.com/ruby/rdoc/pull/1169) 2024-09-02 15:36:53 +00:00
readline.gemspec [ruby/readline] Bump up v0.0.4 2023-12-16 13:49:13 +08:00
readline.rb [ruby/readline] Fix readline-ext gem loading in non Unix-like environments 2023-12-16 13:49:12 +08:00
reline.rb [ruby/reline] Use IO's encoding instead of Encoding.default_external 2024-10-22 14:43:18 +00:00
resolv.gemspec [ruby/resolv] Add spec extensions 2024-09-10 08:33:32 +00:00
resolv.rb Call Resolv::DNS::Config#lazy_initialize explicitly if that instance is not initialized 2024-10-08 15:52:49 +09:00
ruby2_keywords.gemspec
rubygems.rb [rubygems/rubygems] Improve Bundler errors when trying to install to a protected folder in macOS 2024-10-23 08:53:19 +00:00
securerandom.gemspec [ruby/securerandom] Update file list to package 2023-12-29 16:10:30 +00:00
securerandom.rb [ruby/securerandom] Bump up v0.3.1 2023-12-16 12:10:38 +08:00
set.rb Added missing block arg 2024-09-19 16:23:08 +09:00
shellwords.gemspec [ruby/shellwords] Exclude unnecessary files from the packages 2024-07-03 10:15:22 +00:00
shellwords.rb [ruby/shellwords] [DOC] Beautify links and formats 2024-07-03 10:15:26 +00:00
singleton.gemspec
singleton.rb [ruby/singleton] Fixed double assignment 2024-10-02 05:33:31 +00:00
syntax_suggest.rb
tempfile.gemspec [ruby/tempfile] Fix for environment without git 2024-02-27 01:31:12 +00:00
tempfile.rb [ruby/tempfile] Support anonymous tempfile on earlier than Ruby 3.2 2024-08-26 02:49:02 +00:00
time.gemspec [ruby/time] Exclude unnecessary files from package 2024-03-06 15:47:31 +00:00
time.rb [ruby/time] [DOC] Escape the word "Date" that does not mean Date class 2024-10-11 09:59:35 +00:00
timeout.gemspec [ruby/timeout] Provide a 'Changelog' link on rubygems.org/gems/timeout 2023-12-25 21:12:49 +09:00
timeout.rb [ruby/timeout] timeout.rb: Update documentation 2024-08-28 10:58:23 +00:00
tmpdir.gemspec [ruby/tmpdir] Fix for environment without git 2024-02-27 01:31:50 +00:00
tmpdir.rb Perform an actual access check in Dir.tmpdir for writability 2024-10-22 15:17:52 +11:00
tsort.gemspec
tsort.rb
un.gemspec
un.rb
uri.rb Use www.rfc-editor.org for RFC text. 2024-03-28 11:44:45 +09:00
weakref.gemspec
weakref.rb
yaml.rb