Skip to content

Commit

Permalink
More docs and test
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Mar 30, 2020
1 parent aa8d894 commit a1a1a21
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
23 changes: 23 additions & 0 deletions x-pack/plugins/ingest_manager/server/services/saved_object.test.ts
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"`);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

export function escapeSearchQueryPhrase(val: string) {
/**
* 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, '"')}"`;
}

0 comments on commit a1a1a21

Please sign in to comment.