Filter out patterns starting with a comma (#17124) (#17151)

This commit is contained in:
Chris Roberson 2018-03-14 13:05:29 -04:00 committed by GitHub
parent b8fcf06336
commit ea7df636a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View file

@ -19,6 +19,12 @@ describe('getIndices', () => {
expect((await getIndices(null, '*:')).length).toBe(0);
});
it('should ignore a single comma', async () => {
expect((await getIndices(null, ',')).length).toBe(0);
expect((await getIndices(null, ',*')).length).toBe(0);
expect((await getIndices(null, ',foobar')).length).toBe(0);
});
it('should trim the input', async () => {
let index;
const es = {

View file

@ -16,6 +16,11 @@ export async function getIndices(es, rawPattern, limit) {
return [];
}
// ES does not like just a `,*` and will throw a `[string_index_out_of_bounds_exception] String index out of range: 0`
if (pattern.startsWith(',')) {
return [];
}
// We need to always provide a limit and not rely on the default
if (!limit) {
throw '`getIndices()` was called without the required `limit` parameter.';