Skip to content

Commit

Permalink
Merge pull request #610 from sparklemotion/flavorjones-drop-force-enc…
Browse files Browse the repository at this point in the history
…oding

fix: stop force_encoding the page body
  • Loading branch information
flavorjones committed Apr 7, 2023
2 parents 4c8d3d2 + 96a28e7 commit 18ca167
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 0 additions & 4 deletions lib/mechanize/page.rb
Expand Up @@ -41,10 +41,6 @@ def initialize(uri=nil, response=nil, body=nil, code=nil, mech=nil)
@encodings.concat self.class.response_header_charset(response)

if body
# Force the encoding to be 8BIT so we can perform regular expressions.
# We'll set it to the detected encoding later
body.force_encoding(Encoding::ASCII_8BIT)

@encodings.concat self.class.meta_charset body

meta_content_type = self.class.meta_content_type body
Expand Down
14 changes: 14 additions & 0 deletions test/test_mechanize_page.rb
Expand Up @@ -276,5 +276,19 @@ def test_multiple_titles
assert_equal page.title, "HTML>TITLE"
end

def test_frozen_string_body
html = (<<~HTML).freeze
<html>
<head>
<title>Page Title</title>
</head>
<body>
<p>Hello World</p>
</body>
</html>
HTML

html_page(html) # refute_raises
end
end

0 comments on commit 18ca167

Please sign in to comment.