summaryrefslogtreecommitdiff
path: root/lib/rexml/encoding.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-12-09 14:31:47 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-12-09 14:31:47 +0000
commitc9e950b7b88f9103827388f90f30b4ac12faf2a0 (patch)
tree63e3d08f113207c4a6dd623befa2a03236f98e9f /lib/rexml/encoding.rb
parentd0e78ab05dbe5d3015274626fcfb8fee136c8ade (diff)
* 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
Diffstat (limited to 'lib/rexml/encoding.rb')
-rw-r--r--lib/rexml/encoding.rb30
1 files changed, 12 insertions, 18 deletions
diff --git a/lib/rexml/encoding.rb b/lib/rexml/encoding.rb
index 739002dc4a..541e152de0 100644
--- a/lib/rexml/encoding.rb
+++ b/lib/rexml/encoding.rb
@@ -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