diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | lib/rexml/encoding.rb | 4 | ||||
-rw-r--r-- | lib/rexml/source.rb | 6 |
3 files changed, 11 insertions, 6 deletions
@@ -1,3 +1,8 @@ +Fri Aug 25 22:32:04 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] + Fri Aug 25 17:15:17 2006 Yukihiro Matsumoto <matz@ruby-lang.org> * stable version 1.8.5 released. @@ -10,7 +15,7 @@ Tue Aug 22 18:47:51 2006 Yukihiro Matsumoto <matz@ruby-lang.org> * lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser::handle_method): rdoc documents C module methods as instance methods. a patch in - [ruby-core:08536]. + [ruby-core:08536]. Sat Aug 19 14:15:02 2006 NAKAMURA Usaku <usa@ruby-lang.org> diff --git a/lib/rexml/encoding.rb b/lib/rexml/encoding.rb index 644957439e..8acc8a3698 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 cacab221db..c51f504811 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 |