Bug #1449 » ruby19-rexml-encoding-mismatch.diff
lib/rexml/source.rb (作業コピー) | ||
---|---|---|
@line_break = ">"
|
||
end
|
||
super( @source.eof? ? str : str+@source.readline( @line_break ) )
|
||
if !@to_utf and
|
||
@buffer.respond_to?(:force_encoding) and
|
||
@source.respond_to?(:external_encoding) and
|
||
@source.external_encoding != ::Encoding::UTF_8
|
||
@force_utf8 = true
|
||
else
|
||
@force_utf8 = false
|
||
end
|
||
end
|
||
def scan(pattern, cons=false)
|
||
... | ... | |
if rv.size == 0
|
||
until @buffer =~ pattern or @source.nil?
|
||
begin
|
||
# READLINE OPT
|
||
#str = @source.read(@block_size)
|
||
str = @source.readline(@line_break)
|
||
str = decode(str) if @to_utf and str
|
||
@buffer << str
|
||
@buffer << readline
|
||
rescue Iconv::IllegalSequence
|
||
raise
|
||
rescue
|
||
... | ... | |
def read
|
||
begin
|
||
str = @source.readline(@line_break)
|
||
str = decode(str) if @to_utf and str
|
||
@buffer << str
|
||
if not @to_utf and @buffer.respond_to? :force_encoding
|
||
@buffer.force_encoding Encoding::UTF_8
|
||
end
|
||
@buffer << readline
|
||
rescue Exception, NameError
|
||
@source = nil
|
||
end
|
||
... | ... | |
@buffer = $' if cons and rv
|
||
while !rv and @source
|
||
begin
|
||
str = @source.readline(@line_break)
|
||
str = decode(str) if @to_utf and str
|
||
@buffer << str
|
||
@buffer << readline
|
||
rv = pattern.match(@buffer)
|
||
@buffer = $' if cons and rv
|
||
rescue
|
||
... | ... | |
end
|
||
[pos, lineno, line]
|
||
end
|
||
private
|
||
def readline
|
||
str = @source.readline(@line_break)
|
||
return nil if str.nil?
|
||
if @to_utf
|
||
decode(str)
|
||
else
|
||
str.force_encoding(::Encoding::UTF_8) if @force_utf8
|
||
str
|
||
end
|
||
end
|
||
end
|
||
end
|
test/rexml/test_document.rb (作業コピー) | ||
---|---|---|
# -*- coding: utf-8 -*-
|
||
require "rexml/document"
|
||
require "test/unit"
|
||
... | ... | |
ensure
|
||
REXML::Document.entity_expansion_limit = 10000
|
||
end
|
||
def test_tag_in_cdata_with_not_ascii_only_but_ascii8bit_encoding_source
|
||
tag = "<b>...</b>"
|
||
message = "こんにちは、世界!" # Hello world! in Japanese
|
||
xml = <<EOX
|
||
<?xml version="1.0" encoding="UTF-8"?>
|
||
<message><![CDATA[#{tag}#{message}]]></message>
|
||
EOX
|
||
xml.force_encoding(Encoding::ASCII_8BIT)
|
||
doc = REXML::Document.new(xml)
|
||
assert_equal("#{tag}#{message}", doc.root.children.first.value)
|
||
end
|
||
end
|