Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Backslash Escaping for Phrase Searches (#4477)
The add search term button (eg. in the Quick Values view) is adding search terms to the search bar. A search term with spaces will be treated as a phrase and therefor will only surrounded by double quotes. But those phrases did not escape backslashes which is still needed to perform the search. Now phrases will also get the backslashes escaped. Also: Add some tests for adding a search term. Fixes #4111 (cherry picked from commit bfc4a9f)
- Loading branch information
Showing
2 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
graylog2-web-interface/src/stores/search/SearchStore.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import StoreProvider from 'injection/StoreProvider'; | ||
|
||
const SearchStore = StoreProvider.getStore('Search'); | ||
|
||
describe('SearchStore', () => { | ||
beforeEach(() => { | ||
SearchStore.query = ''; | ||
}); | ||
|
||
it('should add a query', () => { | ||
SearchStore.addSearchTerm('field', 'value'); | ||
expect(SearchStore.query).toEqual('field:value'); | ||
}); | ||
|
||
it('should append a new query with "AND"', () => { | ||
SearchStore.addSearchTerm('field1', 'value1'); | ||
SearchStore.addSearchTerm('field2', 'value2'); | ||
expect(SearchStore.query).toEqual('field1:value1 AND field2:value2'); | ||
}); | ||
|
||
describe('escaping', () => { | ||
it('should escape a query with spaces and backslashes', () => { | ||
SearchStore.addSearchTerm('field', '&& || : \\ / + - ! ( ) { } [ ] ^ " ~ * ?'); | ||
expect(SearchStore.query).toEqual('field:"&& || : \\\\ / + - ! ( ) { } [ ] ^ \\" ~ * ?"'); | ||
}); | ||
|
||
it('should escape a query with spaces and backslashes like Windows File Path', () => { | ||
SearchStore.addSearchTerm('field', 'C:\\Program Files\\Atlassian\\Application Data\\Graylog\\log\\some.log'); | ||
expect(SearchStore.query).toEqual('field:"C:\\\\Program Files\\\\Atlassian\\\\Application Data\\\\Graylog\\\\log\\\\some.log"'); | ||
}); | ||
|
||
it('should escape a query with special chars and no spaces', () => { | ||
SearchStore.addSearchTerm('field', '&&||:\\/+-!(){}[]^"~*?'); | ||
expect(SearchStore.query).toEqual('field:\\&&\\||\\:\\\\\\/\\+\\-\\!\\(\\)\\{\\}\\[\\]\\^\\"\\~\\*\\?'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters