Commit 7e106b0f by Torkel Ödegaard Committed by GitHub

Merge pull request #14805 from SamuelToh/11503_prevent_end_of_regexpr

11503: escape measurement filter regex value
parents 0f82fffe 9e3ab71e
import _ from 'lodash';
import kbn from 'app/core/utils/kbn';
function renderTagCondition(tag, index) {
let str = '';
......@@ -43,7 +44,7 @@ export class InfluxQueryBuilder {
} else if (type === 'MEASUREMENTS') {
query = 'SHOW MEASUREMENTS';
if (withMeasurementFilter) {
query += ' WITH MEASUREMENT =~ /' + withMeasurementFilter + '/';
query += ' WITH MEASUREMENT =~ /' + kbn.regexEscape(withMeasurementFilter) + '/';
}
} else if (type === 'FIELDS') {
measurement = this.target.measurement;
......
......@@ -50,6 +50,12 @@ describe('InfluxQueryBuilder', () => {
expect(query).toBe('SHOW MEASUREMENTS WITH MEASUREMENT =~ /something/ LIMIT 100');
});
it('should escape the regex value in measurement query', () => {
const builder = new InfluxQueryBuilder({ measurement: '', tags: [] });
const query = builder.buildExploreQuery('MEASUREMENTS', undefined, 'abc/edf/');
expect(query).toBe('SHOW MEASUREMENTS WITH MEASUREMENT =~ /abc\\/edf\\// LIMIT 100');
});
it('should have WITH MEASUREMENT WHERE in measurement query for non-empty query with tags', () => {
const builder = new InfluxQueryBuilder({
measurement: '',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment