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
8a602e86
Unverified
Commit
8a602e86
authored
Jun 05, 2019
by
kay delaney
Committed by
GitHub
Jun 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Explore: Fixes crash when parsing date math string with whitespace (#17446)
Fixes: #16257
parent
a9da7b5f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
8 deletions
+14
-8
packages/grafana-ui/src/utils/datemath.test.ts
+5
-0
packages/grafana-ui/src/utils/datemath.ts
+9
-8
No files found.
packages/grafana-ui/src/utils/datemath.test.ts
View file @
8a602e86
...
@@ -129,5 +129,10 @@ describe('DateMath', () => {
...
@@ -129,5 +129,10 @@ describe('DateMath', () => {
const
date
=
dateMath
.
parseDateMath
(
'2'
,
dateTime
([
2014
,
1
,
5
]));
const
date
=
dateMath
.
parseDateMath
(
'2'
,
dateTime
([
2014
,
1
,
5
]));
expect
(
date
).
toEqual
(
undefined
);
expect
(
date
).
toEqual
(
undefined
);
});
});
it
(
'should strip whitespace from string'
,
()
=>
{
const
date
=
dateMath
.
parseDateMath
(
' - 2d'
,
dateTime
([
2014
,
1
,
5
]));
expect
(
date
!
.
valueOf
()).
toEqual
(
dateTime
([
2014
,
1
,
3
]).
valueOf
());
});
});
});
});
});
packages/grafana-ui/src/utils/datemath.ts
View file @
8a602e86
...
@@ -87,12 +87,13 @@ export function isValid(text: string | DateTime): boolean {
...
@@ -87,12 +87,13 @@ export function isValid(text: string | DateTime): boolean {
*/
*/
// TODO: Had to revert Andrejs `time: moment.Moment` to `time: any`
// TODO: Had to revert Andrejs `time: moment.Moment` to `time: any`
export
function
parseDateMath
(
mathString
:
string
,
time
:
any
,
roundUp
?:
boolean
):
DateTime
|
undefined
{
export
function
parseDateMath
(
mathString
:
string
,
time
:
any
,
roundUp
?:
boolean
):
DateTime
|
undefined
{
const
strippedMathString
=
mathString
.
replace
(
/
\s
/g
,
''
);
const
dateTime
=
time
;
const
dateTime
=
time
;
let
i
=
0
;
let
i
=
0
;
const
len
=
m
athString
.
length
;
const
len
=
strippedM
athString
.
length
;
while
(
i
<
len
)
{
while
(
i
<
len
)
{
const
c
=
m
athString
.
charAt
(
i
++
);
const
c
=
strippedM
athString
.
charAt
(
i
++
);
let
type
;
let
type
;
let
num
;
let
num
;
let
unit
;
let
unit
;
...
@@ -107,19 +108,19 @@ export function parseDateMath(mathString: string, time: any, roundUp?: boolean):
...
@@ -107,19 +108,19 @@ export function parseDateMath(mathString: string, time: any, roundUp?: boolean):
return
undefined
;
return
undefined
;
}
}
if
(
isNaN
(
parseInt
(
m
athString
.
charAt
(
i
),
10
)))
{
if
(
isNaN
(
parseInt
(
strippedM
athString
.
charAt
(
i
),
10
)))
{
num
=
1
;
num
=
1
;
}
else
if
(
m
athString
.
length
===
2
)
{
}
else
if
(
strippedM
athString
.
length
===
2
)
{
num
=
m
athString
.
charAt
(
i
);
num
=
strippedM
athString
.
charAt
(
i
);
}
else
{
}
else
{
const
numFrom
=
i
;
const
numFrom
=
i
;
while
(
!
isNaN
(
parseInt
(
m
athString
.
charAt
(
i
),
10
)))
{
while
(
!
isNaN
(
parseInt
(
strippedM
athString
.
charAt
(
i
),
10
)))
{
i
++
;
i
++
;
if
(
i
>
10
)
{
if
(
i
>
10
)
{
return
undefined
;
return
undefined
;
}
}
}
}
num
=
parseInt
(
m
athString
.
substring
(
numFrom
,
i
),
10
);
num
=
parseInt
(
strippedM
athString
.
substring
(
numFrom
,
i
),
10
);
}
}
if
(
type
===
0
)
{
if
(
type
===
0
)
{
...
@@ -128,7 +129,7 @@ export function parseDateMath(mathString: string, time: any, roundUp?: boolean):
...
@@ -128,7 +129,7 @@ export function parseDateMath(mathString: string, time: any, roundUp?: boolean):
return
undefined
;
return
undefined
;
}
}
}
}
unit
=
m
athString
.
charAt
(
i
++
);
unit
=
strippedM
athString
.
charAt
(
i
++
);
if
(
!
includes
(
units
,
unit
))
{
if
(
!
includes
(
units
,
unit
))
{
return
undefined
;
return
undefined
;
...
...
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