1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/rexml/encoding.rb (encoding=): give priority to particular

conversion to iconv.  [ruby-core:06520]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@9661 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2005-12-09 14:31:47 +00:00
parent d0e78ab05d
commit c9e950b7b8
5 changed files with 62 additions and 33 deletions

View file

@ -25,28 +25,22 @@ module REXML
begin
$VERBOSE = false
return if defined? @encoding and enc == @encoding
if enc and enc != UTF_8
@encoding = enc.upcase
if enc
raise ArgumentError, "Bad encoding name #{enc}" unless /\A[\w-]+\z/n =~ enc
@encoding = enc.upcase.untaint
else
@encoding = UTF_8
end
err = nil
[@encoding, "ICONV"].each do |enc|
begin
require 'rexml/encodings/ICONV.rb'
Encoding.apply(self, "ICONV")
require File.join("rexml", "encodings", "#{enc}.rb")
return Encoding.apply(self, enc)
rescue LoadError, Exception => err
raise ArgumentError, "Bad encoding name #@encoding" unless @encoding =~ /^[\w-]+$/
@encoding.untaint
enc_file = File.join( "rexml", "encodings", "#@encoding.rb" )
begin
require enc_file
Encoding.apply(self, @encoding)
rescue LoadError
puts $!.message
raise ArgumentError, "No decoder found for encoding #@encoding. Please install iconv."
end
end
else
@encoding = UTF_8
require 'rexml/encodings/UTF-8.rb'
Encoding.apply(self, @encoding)
end
puts err.message
raise ArgumentError, "No decoder found for encoding #@encoding. Please install iconv."
ensure
$VERBOSE = old_verbosity
end