Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not override encoding set during initialisation #1942

Merged
merged 1 commit into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/nokogiri/xml/sax/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ def parse(thing, &block)

###
# Parse given +io+
def parse_io(io, encoding = "ASCII")
@encoding = check_encoding(encoding)
ctx = ParserContext.io(io, ENCODINGS[@encoding])
def parse_io(io, encoding = @encoding)
ctx = ParserContext.io(io, ENCODINGS[check_encoding(encoding)])
yield ctx if block_given?
ctx.parse_with(self)
end
Expand Down
6 changes: 6 additions & 0 deletions test/xml/sax/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ class TestCase
end
end

it :test_parse_io_does_not_override_encoding do
parser = XML::SAX::Parser.new(Doc.new, "UTF-8")
parser.parse_io(StringIO.new("<root/>"), "ASCII")
assert_equal "UTF-8", parser.encoding
end

it :test_parse_with_memory_argument do
parser.parse(File.read(XML_FILE))
refute_empty(parser.document.cdata_blocks)
Expand Down