-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix AggConfig backslash escaping (#193932)
## Summary Fixes `AggConfig` handling to properly escape backslash as well as the single quote it already escapes. (I believe this has been around ever since #2486.) (cherry picked from commit 9916dd0)
- Loading branch information
1 parent
7a872dc
commit 6f44eae
Showing
2 changed files
with
44 additions
and
11 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/plugins/data/common/search/aggs/metrics/lib/get_response_agg_config_class.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,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { getResponseAggId } from './get_response_agg_config_class'; | ||
|
||
describe('getResponseAggConfigClass', () => { | ||
describe('getResponseAggId', () => { | ||
it('should generate a dot-separated ID from parent/key', () => { | ||
const id = getResponseAggId('parent', 'child'); | ||
expect(id).toBe('parent.child'); | ||
}); | ||
|
||
it('should use brackets/quotes if the value includes a dot', () => { | ||
const id = getResponseAggId('parent', 'foo.bar'); | ||
expect(id).toBe(`parent['foo.bar']`); | ||
}); | ||
|
||
it('should escape quotes', () => { | ||
const id = getResponseAggId('parent', `foo.b'ar`); | ||
expect(id).toBe(`parent['foo.b\\'ar']`); | ||
}); | ||
|
||
it('should escape backslashes', () => { | ||
const id = getResponseAggId('parent', `f\\oo.b'ar`); | ||
expect(id).toBe(`parent['f\\\\oo.b\\'ar']`); | ||
}); | ||
}); | ||
}); |
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