diff options
| author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-18 07:07:11 +0000 |
|---|---|---|
| committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-18 07:07:11 +0000 |
| commit | 2f1fa7e402b626fb066798bae91220da8f328fee (patch) | |
| tree | 52b50dd6c5b280998b3b699e5290ff3990d46c24 /lib/rexml/encoding.rb | |
| parent | 40e77949935b5bd43cc4bfac8e055d75519e7da7 (diff) | |
* lib/rexml: Merge fixes since 1.8.6 made solely on the ruby_1_8_6
branch.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16067 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rexml/encoding.rb')
| -rw-r--r-- | lib/rexml/encoding.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/rexml/encoding.rb b/lib/rexml/encoding.rb index e35c3acf7c..a01763be99 100644 --- a/lib/rexml/encoding.rb +++ b/lib/rexml/encoding.rb @@ -56,10 +56,15 @@ module REXML def check_encoding str # We have to recognize UTF-16, LSB UTF-16, and UTF-8 - return UTF_16 if /\A\xfe\xff/n =~ str - return UNILE if /\A\xff\xfe/n =~ str - str =~ /^\s*<?xml\s*version\s*=\s*(['"]).*?\2\s*encoding\s*=\s*(["'])(.*?)\2/um - return $1.upcase if $1 + if str[0] == 0xfe && str[1] == 0xff + str[0,2] = "" + return UTF_16 + elsif str[0] == 0xff && str[1] == 0xfe + str[0,2] = "" + return UNILE + end + str =~ /^\s*<\?xml\s+version\s*=\s*(['"]).*?\1\s+encoding\s*=\s*(["'])(.*?)\2/um + return $3.upcase if $3 return UTF_8 end end |
