Support for lexing empty attribute values.

This ensures that Oga can lex the following properly:

    <input value="" />

Previously Ragel would stop upon finding the empty string. This was caused due
to the string rules being declared as following:

    string_dquote = (dquote ^dquote+ dquote);
    string_squote = (squote ^squote+ squote);

These rules only match strings _with_ content, not without. Since Ragel stops
consuming input the moment it finds unhandled data this resulted in incorrect
tokens being emitted.
This commit is contained in:
Yorick Peterse 2014-09-03 23:10:50 +02:00
parent dc5874f5aa
commit 9b8e9f49c6
3 changed files with 40 additions and 2 deletions

View File

@ -116,8 +116,8 @@
dquote = '"';
squote = "'";
string_dquote = (dquote ^dquote+ dquote);
string_squote = (squote ^squote+ squote);
string_dquote = (dquote ^dquote* dquote);
string_squote = (squote ^squote* squote);
string = string_dquote | string_squote;

View File

@ -53,6 +53,16 @@ describe Oga::XML::Lexer do
]
end
example 'lex an element with an attribute with an empty value' do
lex('<p foo=""></p>').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ATTR, 'foo', 1],
[:T_STRING, '', 1],
[:T_ELEM_END, nil, 1]
]
end
example 'lex a paragraph element with attributes' do
lex('<p class="foo">Hello</p>').should == [
[:T_ELEM_START, nil, 1],

View File

@ -55,6 +55,34 @@ describe Oga::XML::Parser do
end
end
context 'elements with attributes without values' do
before :all do
@element = parse('<foo bar></foo>').children[0]
end
example 'return an Element instance' do
@element.is_a?(Oga::XML::Element).should == true
end
example 'set the bar attribute' do
@element.attribute('bar').value.should be_nil
end
end
context 'elements with attributes with empty values' do
before :all do
@element = parse('<foo bar=""></foo>').children[0]
end
example 'return an Element instance' do
@element.is_a?(Oga::XML::Element).should == true
end
example 'set the bar attribute' do
@element.attribute('bar').value.should == ''
end
end
context 'elements with namespaced attributes' do
before :all do
@element = parse('<foo xmlns:x="x" x:bar="baz"></foo>').children[0]