mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #14405 from IntegersOfK/master
Allow backslash escaping in custom variables
This commit is contained in:
commit
1b6ed5815e
@ -38,8 +38,9 @@ export class CustomVariable implements Variable {
|
||||
}
|
||||
|
||||
updateOptions() {
|
||||
// extract options in comma separated string
|
||||
this.options = _.map(this.query.split(/[,]+/), text => {
|
||||
// extract options in comma separated string (use backslash to escape wanted commas)
|
||||
this.options = _.map(this.query.match(/(?:\\,|[^,])+/g), text => {
|
||||
text = text.replace('\\,', ',');
|
||||
return { text: text.trim(), value: text.trim() };
|
||||
});
|
||||
|
||||
|
@ -151,7 +151,7 @@
|
||||
<h5 class="section-heading">Custom Options</h5>
|
||||
<div class="gf-form">
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -493,15 +493,17 @@ describe('VariableSrv', function(this: any) {
|
||||
scenario.setup(() => {
|
||||
scenario.variableModel = {
|
||||
type: 'custom',
|
||||
query: 'hej, hop, asd',
|
||||
query: 'hej, hop, asd, escaped\\,var',
|
||||
name: 'test',
|
||||
};
|
||||
});
|
||||
|
||||
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[1].value).toBe('hop');
|
||||
expect(scenario.variable.options[2].value).toBe('asd');
|
||||
expect(scenario.variable.options[3].value).toBe('escaped,var');
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user