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:
parent
dc5874f5aa
commit
9b8e9f49c6
|
@ -116,8 +116,8 @@
|
||||||
dquote = '"';
|
dquote = '"';
|
||||||
squote = "'";
|
squote = "'";
|
||||||
|
|
||||||
string_dquote = (dquote ^dquote+ dquote);
|
string_dquote = (dquote ^dquote* dquote);
|
||||||
string_squote = (squote ^squote+ squote);
|
string_squote = (squote ^squote* squote);
|
||||||
|
|
||||||
string = string_dquote | string_squote;
|
string = string_dquote | string_squote;
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,16 @@ describe Oga::XML::Lexer do
|
||||||
]
|
]
|
||||||
end
|
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
|
example 'lex a paragraph element with attributes' do
|
||||||
lex('<p class="foo">Hello</p>').should == [
|
lex('<p class="foo">Hello</p>').should == [
|
||||||
[:T_ELEM_START, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
|
|
|
@ -55,6 +55,34 @@ describe Oga::XML::Parser do
|
||||||
end
|
end
|
||||||
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
|
context 'elements with namespaced attributes' do
|
||||||
before :all do
|
before :all do
|
||||||
@element = parse('<foo xmlns:x="x" x:bar="baz"></foo>').children[0]
|
@element = parse('<foo xmlns:x="x" x:bar="baz"></foo>').children[0]
|
||||||
|
|
Loading…
Reference in New Issue