-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
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
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
23 changes: 23 additions & 0 deletions
23
x-pack/plugins/ingest_manager/server/services/saved_object.test.ts
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,23 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { escapeSearchQueryPhrase } from './saved_object'; | ||
|
||
describe('Saved object service', () => { | ||
describe('escapeSearchQueryPhrase', () => { | ||
it('should return value between quotes', () => { | ||
const res = escapeSearchQueryPhrase('-test'); | ||
|
||
expect(res).toEqual('"-test"'); | ||
}); | ||
|
||
it('should escape quotes', () => { | ||
const res = escapeSearchQueryPhrase('test1"test2'); | ||
|
||
expect(res).toEqual(`"test1\"test2"`); | ||
}); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/ingest_manager/server/services/saved_object.ts
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,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
/** | ||
* Escape a value with double quote to use with saved object search | ||
* Example: escapeSearchQueryPhrase('-test"toto') => '"-test\"toto""' | ||
* @param val | ||
*/ | ||
export function escapeSearchQueryPhrase(val: string): string { | ||
return `"${val.replace(/["]/g, '"')}"`; | ||
} |
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