Fixed counting of newlines in XML declarations

This commit is contained in:
Yorick Peterse 2015-04-15 00:22:58 +02:00
parent b2ea20ba61
commit e942086f2d
2 changed files with 43 additions and 1 deletions

View File

@ -306,19 +306,34 @@
# Machine that processes the contents of an XML declaration tag.
xml_decl := |*
xml_decl_end => {
if ( lines > 0 )
{
advance_line(lines);
lines = 0;
}
callback_simple(id_on_xml_decl_end);
fnext main;
};
# Attributes and their values (e.g. version="1.0").
identifier => {
if ( lines > 0 )
{
advance_line(lines);
lines = 0;
}
callback(id_on_attribute, data, encoding, ts, te);
};
squote => start_string_squote;
dquote => start_string_dquote;
any;
any $count_newlines;
*|;
# Elements

View File

@ -23,5 +23,32 @@ describe Oga::XML::Lexer do
[:T_XML_DECL_END, nil, 1]
]
end
it 'lexes a declaration with a newline after the open tag' do
lex("<?xml\n?>").should == [
[:T_XML_DECL_START, nil, 1],
[:T_XML_DECL_END, nil, 2]
]
end
it 'lexes a declaration with a newline followed by an attribute' do
lex("<?xml\na='b'?>").should == [
[:T_XML_DECL_START, nil, 1],
[:T_ATTR, 'a', 2],
[:T_STRING_SQUOTE, nil, 2],
[:T_STRING_BODY, 'b', 2],
[:T_STRING_SQUOTE, nil, 2],
[:T_XML_DECL_END, nil, 2]
]
end
describe 'using an IO as input' do
it 'lexes a declaration with a newline after the open tag' do
lex_stringio("<?xml\n?>").should == [
[:T_XML_DECL_START, nil, 1],
[:T_XML_DECL_END, nil, 2]
]
end
end
end
end