summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-08-22 15:25:43 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-08-22 15:25:43 +0000
commitcb65426b5140afcc7d051baf88caaa8528cf5c72 (patch)
tree5969a8232a64d3e035ec7d5f7949f2bce8280cee
parent9bb61334fa1cb2236b75d35ee109d1c06727f31e (diff)
downloadruby-cb65426b5140afcc7d051baf88caaa8528cf5c72.tar.gz
ruby-cb65426b5140afcc7d051baf88caaa8528cf5c72.tar.xz
ruby-cb65426b5140afcc7d051baf88caaa8528cf5c72.zip
* lib/rexml/source.rb (REXML::IOSource#initialize): encoding have to
be set with the accessor. fixed: [ruby-list:42737] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@10766 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--lib/rexml/encoding.rb4
-rw-r--r--lib/rexml/source.rb6
3 files changed, 10 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index e90bb2562..4d6587783 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Aug 23 00:25:14 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/rexml/source.rb (REXML::IOSource#initialize): encoding have to
+ be set with the accessor. fixed: [ruby-list:42737]
+
Tue Aug 22 19:21:00 2006 Minero Aoki <aamine@loveruby.net>
* lib/net/smtp.rb: parameter `to_addrs' might be an Array,
diff --git a/lib/rexml/encoding.rb b/lib/rexml/encoding.rb
index 644957439..8acc8a369 100644
--- a/lib/rexml/encoding.rb
+++ b/lib/rexml/encoding.rb
@@ -54,8 +54,8 @@ module REXML
def check_encoding str
# We have to recognize UTF-16, LSB UTF-16, and UTF-8
- return UTF_16 if str[0] == 254 && str[1] == 255
- return UNILE if str[0] == 255 && str[1] == 254
+ return UTF_16 if /\A\xfe\xff/n =~ str
+ return UNILE if /\A\xff\xfe/n =~ str
str =~ /^\s*<?xml\s*version=(['"]).*?\2\s*encoding=(["'])(.*?)\2/um
return $1.upcase if $1
return UTF_8
diff --git a/lib/rexml/source.rb b/lib/rexml/source.rb
index cacab221d..c51f50481 100644
--- a/lib/rexml/source.rb
+++ b/lib/rexml/source.rb
@@ -135,14 +135,14 @@ module REXML
# the XML spec. If there is one, we can determine the encoding from
# it.
str = @source.read( 2 )
- if (str[0] == 254 && str[1] == 255) || (str[0] == 255 && str[1] == 254)
- @encoding = check_encoding( str )
+ if /\A(?:\xfe\xff|\xff\xfe)/n =~ str
+ self.encoding = check_encoding( str )
@line_break = encode( '>' )
else
@line_break = '>'
end
super str+@source.readline( @line_break )
- end
+ end
def scan(pattern, cons=false)
rv = super