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
375cc8de
Unverified
Commit
375cc8de
authored
Mar 30, 2018
by
Carl Bergquist
Committed by
GitHub
Mar 30, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11399 from roidelapluie/promba
Fix #10555 #6888 Backslash in Prometheus variables
parents
b41370ca
1f1719c4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
4 deletions
+45
-4
public/app/plugins/datasource/prometheus/datasource.ts
+7
-3
public/app/plugins/datasource/prometheus/specs/datasource.jest.ts
+38
-1
No files found.
public/app/plugins/datasource/prometheus/datasource.ts
View file @
375cc8de
...
@@ -6,8 +6,12 @@ import * as dateMath from 'app/core/utils/datemath';
...
@@ -6,8 +6,12 @@ import * as dateMath from 'app/core/utils/datemath';
import
PrometheusMetricFindQuery
from
'./metric_find_query'
;
import
PrometheusMetricFindQuery
from
'./metric_find_query'
;
import
{
ResultTransformer
}
from
'./result_transformer'
;
import
{
ResultTransformer
}
from
'./result_transformer'
;
function
prometheusSpecialRegexEscape
(
value
)
{
export
function
prometheusRegularEscape
(
value
)
{
return
value
.
replace
(
/
[\\
^$*+?.()|[
\]
{}
]
/g
,
'
\\\\
$&'
);
return
value
.
replace
(
/'/g
,
"
\\\\
'"
);
}
export
function
prometheusSpecialRegexEscape
(
value
)
{
return
prometheusRegularEscape
(
value
.
replace
(
/
\\
/g
,
'
\\\\\\\
\'
).replace(/[$^*{}
\
[
\
]+?.()]/g, '
\\\\
$
&
'));
}
}
export class PrometheusDatasource {
export class PrometheusDatasource {
...
@@ -80,7 +84,7 @@ export class PrometheusDatasource {
...
@@ -80,7 +84,7 @@ export class PrometheusDatasource {
interpolateQueryExpr(value, variable, defaultFormatFn) {
interpolateQueryExpr(value, variable, defaultFormatFn) {
// if no multi or include all do not regexEscape
// if no multi or include all do not regexEscape
if (!variable.multi && !variable.includeAll) {
if (!variable.multi && !variable.includeAll) {
return
value
;
return
prometheusRegularEscape(value)
;
}
}
if (typeof value === '
string
') {
if (typeof value === '
string
') {
...
...
public/app/plugins/datasource/prometheus/specs/datasource.jest.ts
View file @
375cc8de
import
_
from
'lodash'
;
import
_
from
'lodash'
;
import
moment
from
'moment'
;
import
moment
from
'moment'
;
import
q
from
'q'
;
import
q
from
'q'
;
import
{
PrometheusDatasource
}
from
'../datasource'
;
import
{
PrometheusDatasource
,
prometheusSpecialRegexEscape
,
prometheusRegularEscape
}
from
'../datasource'
;
describe
(
'PrometheusDatasource'
,
()
=>
{
describe
(
'PrometheusDatasource'
,
()
=>
{
let
ctx
:
any
=
{};
let
ctx
:
any
=
{};
...
@@ -101,4 +101,41 @@ describe('PrometheusDatasource', () => {
...
@@ -101,4 +101,41 @@ describe('PrometheusDatasource', () => {
});
});
});
});
});
});
describe
(
'Prometheus regular escaping'
,
function
()
{
it
(
'should not escape simple string'
,
function
()
{
expect
(
prometheusRegularEscape
(
'cryptodepression'
)).
toEqual
(
'cryptodepression'
);
});
it
(
"should escape '"
,
function
()
{
expect
(
prometheusRegularEscape
(
"looking'glass"
)).
toEqual
(
"looking
\\\\
'glass"
);
});
it
(
'should escape multiple characters'
,
function
()
{
expect
(
prometheusRegularEscape
(
"'looking'glass'"
)).
toEqual
(
"
\\\\
'looking
\\\\
'glass
\\\\
'"
);
});
});
describe
(
'Prometheus regexes escaping'
,
function
()
{
it
(
'should not escape simple string'
,
function
()
{
expect
(
prometheusSpecialRegexEscape
(
'cryptodepression'
)).
toEqual
(
'cryptodepression'
);
});
it
(
'should escape $^*+?.()
\
\'
, function() {
expect(prometheusSpecialRegexEscape("looking'
glass
")).toEqual("
looking
\\\\
'glass");
expect(prometheusSpecialRegexEscape('
looking
{
glass
')).toEqual('
looking
\\\\
{
glass
');
expect(prometheusSpecialRegexEscape('
looking
}
glass
')).toEqual('
looking
\\\\
}
glass
');
expect(prometheusSpecialRegexEscape('
looking
[
glass
')).toEqual('
looking
\\\\
[
glass
');
expect(prometheusSpecialRegexEscape('
looking
]
glass
')).toEqual('
looking
\\\\
]
glass
');
expect(prometheusSpecialRegexEscape('
looking$glass
')).toEqual('
looking
\\\\
$glass
');
expect(prometheusSpecialRegexEscape('
looking
^
glass
')).toEqual('
looking
\\\\
^
glass
');
expect(prometheusSpecialRegexEscape('
looking
*
glass
')).toEqual('
looking
\\\\
*
glass
');
expect(prometheusSpecialRegexEscape('
looking
+
glass
')).toEqual('
looking
\\\\
+
glass
');
expect(prometheusSpecialRegexEscape('
looking
?
glass
')).toEqual('
looking
\\\\
?
glass
');
expect(prometheusSpecialRegexEscape('
looking
.
glass
')).toEqual('
looking
\\\\
.
glass
');
expect(prometheusSpecialRegexEscape('
looking
(
glass
')).toEqual('
looking
\\\\
(
glass
');
expect(prometheusSpecialRegexEscape('
looking
)
glass
')).toEqual('
looking
\\\\
)
glass
');
expect(prometheusSpecialRegexEscape('
looking
\\
glass
')).toEqual('
looking
\\\\\\\\
glass
');
});
it('
should
escape
multiple
special
characters
', function() {
expect(prometheusSpecialRegexEscape('
+
looking$glass
?
')).toEqual('
\\\\
+
looking
\\\\
$glass
\\\\
?
');
});
});
});
});
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