Skip to content
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
2 changes: 2 additions & 0 deletions lib/rexml/parsers/baseparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ def pull_event
else
raise REXML::ParseException.new("Malformed node: Started with '<!' but not a comment nor ELEMENT,ENTITY,ATTLIST,NOTATION", @source)
end
elsif @source.match?("<?", true)
return process_instruction
elsif match = @source.match(/(%.*?;)\s*/um, true)
return [ :externalentity, match[1] ]
elsif @source.match?(/\]\s*>/um, true)
Expand Down
9 changes: 9 additions & 0 deletions test/parse/test_document_type_declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ def test_notation_attlist
doctype.children.collect(&:class))
end

def test_instruction_element
doctype = parse(<<-INTERNAL_SUBSET)
<?target content?>
<!ELEMENT element-name EMPTY>
INTERNAL_SUBSET
assert_equal([REXML::Instruction, REXML::ElementDecl],
doctype.children.collect(&:class))
end

private
def parse(internal_subset)
super(<<-DOCTYPE)
Expand Down
31 changes: 31 additions & 0 deletions test/parse/test_processing_instruction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ def test_xml_declaration_not_at_document_start
DETAIL
end

def test_xml_declaration_in_internal_subset
exception = assert_raise(REXML::ParseException) do
parse(<<-XML)
<!DOCTYPE r [
<?xml version="1.0"?>
]>
<r/>
XML
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed XML: XML declaration is not at the start
Line: 2
Position: 35
Last 80 unconsumed characters:
version="1.0"?>
DETAIL
end

def test_xml_declaration_missing_spaces
exception = assert_raise(REXML::ParseException) do
parser = REXML::Parsers::BaseParser.new('<?xml?>')
Expand Down Expand Up @@ -229,6 +247,19 @@ def test_after_root
assert_equal("abc", events[:processing_instruction])
end

def test_in_internal_subset
doc = parse(<<-XML)
<!DOCTYPE r [
<?x y?>
<!ELEMENT r EMPTY>
]>
<r/>
XML
instruction = doc.doctype.children.first
assert_equal(["x", "y"],
[instruction.target, instruction.content])
end

def test_content_question
document = REXML::Document.new("<a><?name con?tent?></a>")
assert_equal("con?tent", document.root.children.first.content)
Expand Down