]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
fix charset detection
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sun, 1 Apr 2007 17:15:50 +0000 (17:15 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sun, 1 Apr 2007 17:15:50 +0000 (17:15 +0000)
lib/rbot/core/utils/extends.rb

index 5fa24dcbd331f44467d1fc0236c09c8f2759a21c..fa2dff9515c3291e099453e579f58043c507d553 100644 (file)
@@ -54,7 +54,7 @@ class ::String
     charset = nil
 
     if self.respond_to?(:http_headers) and headers = self.http_headers
-      if headers['content-type'].first.match(/charset="?(\S+?)"?\s*;?/i)
+      if headers['content-type'].first.match(/charset=(\S+?)\s*(?:;|\Z)/i)
         debug "charset #{charset} set from header"
         charset = $1
       end
@@ -64,7 +64,7 @@ class ::String
       case self
       when /<\?xml.*encoding="(\S+)".*\?>/i
         charset = $1
-      when /<meta\s+http-equiv\s*=\s*"Content-Type".*charset\s*=\s*"?(\S+?)"?\s*;?/i
+      when /<meta\s+http-equiv\s*=\s*["']?Content-Type["']?.*charset\s*=\s*(\S+?)(?:;|["']|\s).*>/i
         charset = $1
       end
       debug "charset #{charset} set from string"