1
* REXML should accept UTF-16. [ruby-list:42737]
3
diff -ruN ruby-1.8.5.orig/lib/rexml/encoding.rb ruby-1.8.5/lib/rexml/encoding.rb
4
--- ruby-1.8.5.orig/lib/rexml/encoding.rb 2006-04-14 11:56:43.000000000 +0900
5
+++ ruby-1.8.5/lib/rexml/encoding.rb 2006-09-19 13:41:16.000000000 +0900
9
# We have to recognize UTF-16, LSB UTF-16, and UTF-8
10
- return UTF_16 if str[0] == 254 && str[1] == 255
11
- return UNILE if str[0] == 255 && str[1] == 254
12
+ return UTF_16 if /\A\xfe\xff/n =~ str
13
+ return UNILE if /\A\xff\xfe/n =~ str
14
str =~ /^\s*<?xml\s*version=(['"]).*?\2\s*encoding=(["'])(.*?)\2/um
15
return $1.upcase if $1
17
diff -ruN ruby-1.8.5.orig/lib/rexml/source.rb ruby-1.8.5/lib/rexml/source.rb
18
--- ruby-1.8.5.orig/lib/rexml/source.rb 2006-04-14 11:56:43.000000000 +0900
19
+++ ruby-1.8.5/lib/rexml/source.rb 2006-09-19 13:41:16.000000000 +0900
21
# the XML spec. If there is one, we can determine the encoding from
23
str = @source.read( 2 )
24
- if (str[0] == 254 && str[1] == 255) || (str[0] == 255 && str[1] == 254)
25
- @encoding = check_encoding( str )
26
+ if /\A(?:\xfe\xff|\xff\xfe)/n =~ str
27
+ self.encoding = check_encoding( str )
28
@line_break = encode( '>' )
32
super str+@source.readline( @line_break )
36
def scan(pattern, cons=false)