Permalink
Browse files

Fix charset name extraction. Issue #180

  • Loading branch information...
knu committed Jan 3, 2012
1 parent 1561fae commit e4e9cbb375a9d1362f3c19853decad00e8dd04f5
Showing with 8 additions and 1 deletion.
  1. +1 −0 CHANGELOG.rdoc
  2. +1 −1 lib/mechanize/page.rb
  3. +6 −0 test/test_mechanize_page_encoding.rb
View
@@ -4,6 +4,7 @@
* Bug fixes
* Meta refresh URIs are now escaped (excluding %). Issue #177
+ * Fix charset name extraction. Issue #180
=== 2.1 / 2011-12-20
View
@@ -365,7 +365,7 @@ def labels_hash
end
def self.charset content_type
- charset = content_type[/charset=([^; ]+)/i, 1]
+ charset = content_type[/;\s*charset\s*=\s*([^()<>@,;:\\\"\/\[\]?={}\s]+)/i, 1]
return nil if charset == 'none'
charset
end
@@ -23,6 +23,12 @@ def util_page body = @body, headers = @response_headers
def test_page_charset
charset = Mechanize::Page.charset 'text/html;charset=vAlue'
assert_equal 'vAlue', charset
+
+ charset = Mechanize::Page.charset 'text/html;charset=vaLue, text/html'
+ assert_equal 'vaLue', charset
+
+ charset = Mechanize::Page.charset 'text/html ; charset = valUe, text/html'
+ assert_equal 'valUe', charset
end
def test_page_charset_upcase

0 comments on commit e4e9cbb

Please sign in to comment.