Skip to content

Commit

Permalink
disallow empty attribute names in query language (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkKoester authored May 15, 2020
1 parent 6a0b228 commit e27e73d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
4 changes: 3 additions & 1 deletion grammar.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ attr
= "[" _ v:attrValue _ "]" { return v; }
attrOps = a:[><!]? "=" { return (a || '') + '='; } / [><]
attrEqOps = a:"!"? "=" { return (a || '') + '='; }
attrName = i:(identifierName / ".")+ { return i.join(''); }
attrName = a:identifierName as:("." identifierName)* {
return [].concat.apply([a], as).join('');
}
attrValue
= name:attrName _ op:attrEqOps _ value:(type / regex) {
return { type: 'attribute', name: name, operator: op, value: value };
Expand Down
8 changes: 0 additions & 8 deletions tests/queryAttribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ describe('Attribute query', function () {
]);
});

// Not sure what AST would be producing an empty string, so
// just checking this acceptable grammar doesn't fail and is
// covered.
it('literal with empty string and dot', function () {
const matches = esquery(literal, 'Literal[.value=\'abc\']');
assert.lengthOf(matches, 0);
});

it('literal with backslashes', function () {
const matches = esquery(literal, 'Literal[value="\\z"]');
assert.includeMembers(matches, [
Expand Down

0 comments on commit e27e73d

Please sign in to comment.