mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fix(elasticsearch): fixed proper json escaping for lucene query, fixes #2981
This commit is contained in:
@@ -159,7 +159,10 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
|
|||||||
if (target.hide) {return;}
|
if (target.hide) {return;}
|
||||||
|
|
||||||
var esQuery = angular.toJson(this.queryBuilder.build(target));
|
var esQuery = angular.toJson(this.queryBuilder.build(target));
|
||||||
esQuery = esQuery.replace("$lucene_query", target.query || '*');
|
var luceneQuery = angular.toJson(target.query || '*');
|
||||||
|
// remove inner quotes
|
||||||
|
luceneQuery = luceneQuery.substr(1, luceneQuery.length - 2);
|
||||||
|
esQuery = esQuery.replace("$lucene_query", luceneQuery);
|
||||||
|
|
||||||
payload += header + '\n' + esQuery + '\n';
|
payload += header + '\n' + esQuery + '\n';
|
||||||
sentTargets.push(target);
|
sentTargets.push(target);
|
||||||
|
|||||||
@@ -42,16 +42,15 @@ describe('ElasticDatasource', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('When issueing metric query with interval pattern', function() {
|
describe('When issueing metric query with interval pattern', function() {
|
||||||
|
var requestOptions, parts, header;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
ctx.ds = new ctx.service({
|
ctx.ds = new ctx.service({
|
||||||
url: 'http://es.com',
|
url: 'http://es.com',
|
||||||
index: '[asd-]YYYY.MM.DD',
|
index: '[asd-]YYYY.MM.DD',
|
||||||
jsonData: { interval: 'Daily' }
|
jsonData: { interval: 'Daily' }
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('should translate index pattern to current day', function() {
|
|
||||||
var requestOptions;
|
|
||||||
ctx.backendSrv.datasourceRequest = function(options) {
|
ctx.backendSrv.datasourceRequest = function(options) {
|
||||||
requestOptions = options;
|
requestOptions = options;
|
||||||
return ctx.$q.when({data: {responses: []}});
|
return ctx.$q.when({data: {responses: []}});
|
||||||
@@ -62,13 +61,22 @@ describe('ElasticDatasource', function() {
|
|||||||
from: moment([2015, 4, 30, 10]),
|
from: moment([2015, 4, 30, 10]),
|
||||||
to: moment([2015, 5, 1, 10])
|
to: moment([2015, 5, 1, 10])
|
||||||
},
|
},
|
||||||
targets: [{ bucketAggs: [], metrics: [] }]
|
targets: [{ bucketAggs: [], metrics: [], query: 'escape\\:test' }]
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.$rootScope.$apply();
|
ctx.$rootScope.$apply();
|
||||||
var parts = requestOptions.data.split('\n');
|
|
||||||
var header = angular.fromJson(parts[0]);
|
parts = requestOptions.data.split('\n');
|
||||||
|
header = angular.fromJson(parts[0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should translate index pattern to current day', function() {
|
||||||
expect(header.index).to.eql(['asd-2015.05.30', 'asd-2015.05.31', 'asd-2015.06.01']);
|
expect(header.index).to.eql(['asd-2015.05.30', 'asd-2015.05.31', 'asd-2015.06.01']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should json escape lucene query', function() {
|
||||||
|
var body = angular.fromJson(parts[1]);
|
||||||
|
expect(body.query.filtered.query.query_string.query).to.be('escape\\:test');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ declare var IndexPattern: any;
|
|||||||
|
|
||||||
describe('IndexPattern', function() {
|
describe('IndexPattern', function() {
|
||||||
|
|
||||||
describe.only('when getting index for today', function() {
|
describe('when getting index for today', function() {
|
||||||
it('should return correct index name', function() {
|
it('should return correct index name', function() {
|
||||||
var pattern = new IndexPattern('[asd-]YYYY.MM.DD', 'Daily');
|
var pattern = new IndexPattern('[asd-]YYYY.MM.DD', 'Daily');
|
||||||
var expected = 'asd-' + moment().format('YYYY.MM.DD');
|
var expected = 'asd-' + moment().format('YYYY.MM.DD');
|
||||||
|
|||||||
Reference in New Issue
Block a user