Skip to content

Commit

Permalink
Bug/773 search bar boolean matching (#776)
Browse files Browse the repository at this point in the history
* Match against boolean values when they're not part of a word

* revert formatting change to Exp.boolean

* Remove console.log statement

* changelog

* Add test case for regression
  • Loading branch information
chandlerprall authored May 7, 2018
1 parent e0110c3 commit b29bbea
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Added aria-live labeling for `EuiToasts` ([#777](https://github.com/elastic/eui/pull/777))
- Added aria labeling requirements for `EuiBadge` , as well as a generic prop_type function `requiresAriaLabel` in `utils` to check for it. ([#777](https://github.com/elastic/eui/pull/777))
- Ensure switches’ inputs are still hidden when `[disabled]` ([#778](https://github.com/elastic/eui/pull/778))
- Made boolean matching in `EuiSearchBar` more exact so it doesn't match words starting with booleans, like "truest" or "offer" ([#776](https://github.com/elastic/eui/pull/776))

## [`0.0.46`](https://github.com/elastic/eui/tree/v0.0.46)

Expand Down
7 changes: 6 additions & 1 deletion src/components/search_bar/query/default_syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ rangeValue
containsValue
= number
/ date
/ boolean
/ booleanWord
/ word
/ phrase
Expand All @@ -136,6 +136,11 @@ escapedChar
reservedChar
= [\-:\\\\]
// only match booleans followed by whitespace or end of input
booleanWord
= bool:boolean &space { return bool; }
/ bool:boolean !. { return bool; }
boolean
= [tT][rR][uU][eE] { return Exp.boolean(text(), location()); }
/ [fF][aA][lL][sS][eE] { return Exp.boolean(text(), location()); }
Expand Down
16 changes: 16 additions & 0 deletions src/components/search_bar/query/default_syntax.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,22 @@ describe('defaultSyntax', () => {
expect(printedQuery).toBe(query);
});

test('boolean word boundary', () => {
const query = `active:truest`;
const ast = defaultSyntax.parse(query);

expect(ast).toBeDefined();
expect(ast.clauses).toHaveLength(1);

const clause = ast.getSimpleFieldClause('active');
expect(clause).toBeDefined();
expect(AST.Field.isInstance(clause)).toBe(true);
expect(AST.Match.isMustClause(clause)).toBe(true);
expect(AST.Operator.isEQClause(clause)).toBe(true);
expect(clause.field).toBe('active');
expect(clause.value).toBe('truest');
});

test('number range expressions', () => {

const query = `num1>6 -num2>=8 num3<4 -num4<=2`;
Expand Down

0 comments on commit b29bbea

Please sign in to comment.