Merge pull request #14405 from IntegersOfK/master

Allow backslash escaping in custom variables
This commit is contained in:
Carl Bergquist 2018-12-10 07:40:18 +01:00 committed by GitHub
commit 1b6ed5815e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 5 deletions

View File

@ -38,8 +38,9 @@ export class CustomVariable implements Variable {
} }
updateOptions() { updateOptions() {
// extract options in comma separated string // extract options in comma separated string (use backslash to escape wanted commas)
this.options = _.map(this.query.split(/[,]+/), text => { this.options = _.map(this.query.match(/(?:\\,|[^,])+/g), text => {
text = text.replace('\\,', ',');
return { text: text.trim(), value: text.trim() }; return { text: text.trim(), value: text.trim() };
}); });

View File

@ -151,7 +151,7 @@
<h5 class="section-heading">Custom Options</h5> <h5 class="section-heading">Custom Options</h5>
<div class="gf-form"> <div class="gf-form">
<span class="gf-form-label width-14">Values separated by comma</span> <span class="gf-form-label width-14">Values separated by comma</span>
<input type="text" class="gf-form-input" ng-model='current.query' ng-blur="runQuery()" placeholder="1, 10, 20, myvalue" <input type="text" class="gf-form-input" ng-model='current.query' ng-blur="runQuery()" placeholder="1, 10, 20, myvalue, escaped\,value"
required></input> required></input>
</div> </div>
</div> </div>

View File

@ -493,15 +493,17 @@ describe('VariableSrv', function(this: any) {
scenario.setup(() => { scenario.setup(() => {
scenario.variableModel = { scenario.variableModel = {
type: 'custom', type: 'custom',
query: 'hej, hop, asd', query: 'hej, hop, asd, escaped\\,var',
name: 'test', name: 'test',
}; };
}); });
it('should update options array', () => { it('should update options array', () => {
expect(scenario.variable.options.length).toBe(3); expect(scenario.variable.options.length).toBe(4);
expect(scenario.variable.options[0].text).toBe('hej'); expect(scenario.variable.options[0].text).toBe('hej');
expect(scenario.variable.options[1].value).toBe('hop'); expect(scenario.variable.options[1].value).toBe('hop');
expect(scenario.variable.options[2].value).toBe('asd');
expect(scenario.variable.options[3].value).toBe('escaped,var');
}); });
}); });