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
21ed77d7
Unverified
Commit
21ed77d7
authored
Oct 12, 2020
by
Torkel Ödegaard
Committed by
GitHub
Oct 12, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TemplateSrv: Fix interpolating strings with object variables (#28171)
parent
92c2a6c2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
0 deletions
+40
-0
public/app/features/templating/template_srv.test.ts
+31
-0
public/app/features/templating/template_srv.ts
+9
-0
No files found.
public/app/features/templating/template_srv.test.ts
View file @
21ed77d7
...
...
@@ -687,4 +687,35 @@ describe('templateSrv', () => {
expect
(
target
).
toBe
(
'2020-07'
);
});
});
describe
(
'handle objects gracefully'
,
()
=>
{
beforeEach
(()
=>
{
initTemplateSrv
([{
type
:
'query'
,
name
:
'test'
,
current
:
{
value
:
{
test
:
'A'
}
}
}]);
});
it
(
'should not pass object to custom function'
,
()
=>
{
let
passedValue
:
any
=
null
;
_templateSrv
.
replace
(
'this.${test}.filters'
,
{},
(
value
:
any
)
=>
{
passedValue
=
value
;
});
expect
(
passedValue
).
toBe
(
'[object Object]'
);
});
});
describe
(
'handle objects gracefully and call toString if defined'
,
()
=>
{
beforeEach
(()
=>
{
const
value
=
{
test
:
'A'
,
toString
:
()
=>
'hello'
};
initTemplateSrv
([{
type
:
'query'
,
name
:
'test'
,
current
:
{
value
}
}]);
});
it
(
'should not pass object to custom function'
,
()
=>
{
let
passedValue
:
any
=
null
;
_templateSrv
.
replace
(
'this.${test}.filters'
,
{},
(
value
:
any
)
=>
{
passedValue
=
value
;
});
expect
(
passedValue
).
toBe
(
'hello'
);
});
});
});
public/app/features/templating/template_srv.ts
View file @
21ed77d7
...
...
@@ -112,6 +112,15 @@ export class TemplateSrv implements BaseTemplateSrv {
// for some scopedVars there is no variable
variable
=
variable
||
{};
if
(
value
===
null
||
value
===
undefined
)
{
return
''
;
}
// if it's an object transform value to string
if
(
!
Array
.
isArray
(
value
)
&&
typeof
value
===
'object'
)
{
value
=
`
${
value
}
`
;
}
if
(
typeof
format
===
'function'
)
{
return
format
(
value
,
variable
,
this
.
formatValue
);
}
...
...
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