diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a6728405d0f..47d55dd0fe86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ **Breaking changes** +- Changed `EuiSearchBar` to preserve phrases with leading and trailing spaces, instead of dropping surrounding whitespace ([#5514](https://github.com/elastic/eui/pull/5514)) - Removed `data-test-subj="dataGridWrapper"` from `EuiDataGrid` in favor of `data-test-subj="euiDataGridBody"` ([#5506](https://github.com/elastic/eui/pull/5506)) ## [`44.0.0`](https://github.com/elastic/eui/tree/v44.0.0) diff --git a/src/components/search_bar/query/default_syntax.test.ts b/src/components/search_bar/query/default_syntax.test.ts index df51fdc8f26d..0114d50582f1 100644 --- a/src/components/search_bar/query/default_syntax.test.ts +++ b/src/components/search_bar/query/default_syntax.test.ts @@ -562,8 +562,8 @@ describe('defaultSyntax', () => { expect(printedQuery).toBe(query); }); - test('relaxed phrases with spaces', () => { - const query = 'f:" this is a relaxed phrase \t"'; + test('phrases with spaces', () => { + const query = 'f:" this is a phrase that preserves spaces\t"'; const ast = defaultSyntax.parse(query); expect(ast).toBeDefined(); @@ -574,10 +574,10 @@ describe('defaultSyntax', () => { expect(AST.Field.isInstance(clause)).toBe(true); expect(AST.Match.isMustClause(clause)).toBe(true); expect(clause.field).toBe('f'); - expect(clause.value).toBe('this is a relaxed phrase'); + expect(clause.value).toBe(' this is a phrase that preserves spaces '); const printedQuery = defaultSyntax.print(ast); - expect(printedQuery).toBe('f:"this is a relaxed phrase"'); + expect(printedQuery).toBe('f:" this is a phrase that preserves spaces "'); }); test('phrases with extra characters', () => { diff --git a/src/components/search_bar/query/default_syntax.ts b/src/components/search_bar/query/default_syntax.ts index 0e054276891f..d538b5295754 100644 --- a/src/components/search_bar/query/default_syntax.ts +++ b/src/components/search_bar/query/default_syntax.ts @@ -146,9 +146,9 @@ containsValue / word phrase - = '"' space? phrase:( - (phraseWord+)? (space phraseWord+)* { return unescapePhraseValue(text()); } - ) space? '"' { return Exp.string(phrase, location()); } + = '"' phrase:( + space? (phraseWord+)? (space phraseWord+)* space? { return unescapePhraseValue(text()); } + ) '"' { return Exp.string(phrase, location()); } phraseWord // not a backslash, quote, or space