Skip to content

Commit e27e73d

Browse files
authored
disallow empty attribute names in query language (#108)
1 parent 6a0b228 commit e27e73d

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

grammar.pegjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ attr
5959
= "[" _ v:attrValue _ "]" { return v; }
6060
attrOps = a:[><!]? "=" { return (a || '') + '='; } / [><]
6161
attrEqOps = a:"!"? "=" { return (a || '') + '='; }
62-
attrName = i:(identifierName / ".")+ { return i.join(''); }
62+
attrName = a:identifierName as:("." identifierName)* {
63+
return [].concat.apply([a], as).join('');
64+
}
6365
attrValue
6466
= name:attrName _ op:attrEqOps _ value:(type / regex) {
6567
return { type: 'attribute', name: name, operator: op, value: value };

tests/queryAttribute.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,6 @@ describe('Attribute query', function () {
5757
]);
5858
});
5959

60-
// Not sure what AST would be producing an empty string, so
61-
// just checking this acceptable grammar doesn't fail and is
62-
// covered.
63-
it('literal with empty string and dot', function () {
64-
const matches = esquery(literal, 'Literal[.value=\'abc\']');
65-
assert.lengthOf(matches, 0);
66-
});
67-
6860
it('literal with backslashes', function () {
6961
const matches = esquery(literal, 'Literal[value="\\z"]');
7062
assert.includeMembers(matches, [

0 commit comments

Comments
 (0)