Commit 1b6ed581 by Carl Bergquist Committed by GitHub

Merge pull request #14405 from IntegersOfK/master

Allow backslash escaping in custom variables
parents e61d8770 6c95acc8
...@@ -38,8 +38,9 @@ export class CustomVariable implements Variable { ...@@ -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() };
}); });
......
...@@ -151,7 +151,7 @@ ...@@ -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>
......
...@@ -493,15 +493,17 @@ describe('VariableSrv', function(this: any) { ...@@ -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');
}); });
}); });
......
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