Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
6b25453f
Commit
6b25453f
authored
Jul 21, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
templating(influxdb): regex escape values when multi or all format is enabled, closes #2373
parent
06a32ce7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
2 deletions
+32
-2
public/app/features/templating/templateValuesSrv.js
+19
-2
public/test/specs/templateValuesSrv-specs.js
+13
-0
No files found.
public/app/features/templating/templateValuesSrv.js
View file @
6b25453f
...
...
@@ -223,10 +223,25 @@ function (angular, _, kbn) {
}
return
_
.
map
(
_
.
keys
(
options
).
sort
(),
function
(
key
)
{
return
{
text
:
key
,
value
:
key
};
var
option
=
{
text
:
key
,
value
:
key
};
// check if values need to be regex escaped
if
(
self
.
shouldRegexEscape
(
variable
))
{
option
.
value
=
self
.
regexEscape
(
option
.
value
);
}
return
option
;
});
};
this
.
shouldRegexEscape
=
function
(
variable
)
{
return
(
variable
.
includeAll
||
variable
.
multi
)
&&
variable
.
allFormat
.
indexOf
(
'regex'
)
!==
-
1
;
};
this
.
regexEscape
=
function
(
value
)
{
return
value
.
replace
(
/
[
-[
\]
{}()*+!<=:?.
\/\\
^$|#
\s
,
]
/g
,
'
\\
$&'
);
};
this
.
addAllOption
=
function
(
variable
)
{
var
allValue
=
''
;
switch
(
variable
.
allFormat
)
{
...
...
@@ -237,7 +252,9 @@ function (angular, _, kbn) {
allValue
=
'.*'
;
break
;
case
'regex values'
:
allValue
=
'('
+
_
.
pluck
(
variable
.
options
,
'text'
).
join
(
'|'
)
+
')'
;
allValue
=
'('
+
_
.
map
(
variable
.
options
,
function
(
option
)
{
return
self
.
regexEscape
(
option
.
text
);
}).
join
(
'|'
)
+
')'
;
break
;
default
:
allValue
=
'{'
;
...
...
public/test/specs/templateValuesSrv-specs.js
View file @
6b25453f
...
...
@@ -322,6 +322,19 @@ define([
});
});
describeUpdateVariable
(
'with include all regex values and values require escaping'
,
function
(
scenario
)
{
scenario
.
setup
(
function
()
{
scenario
.
variable
=
{
type
:
'query'
,
query
:
'apps.*'
,
name
:
'test'
,
includeAll
:
true
,
allFormat
:
'regex values'
};
scenario
.
queryResult
=
[{
text
:
'/root'
},
{
text
:
'/var'
},
{
text
:
'/lib'
}];
});
it
(
'should regex escape options'
,
function
()
{
expect
(
scenario
.
variable
.
options
[
0
].
value
).
to
.
be
(
'(
\\
/lib|
\\
/root|
\\
/var)'
);
expect
(
scenario
.
variable
.
options
[
1
].
value
).
to
.
be
(
'
\\
/lib'
);
expect
(
scenario
.
variable
.
options
[
1
].
text
).
to
.
be
(
'/lib'
);
});
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment