Skip to content

Commit d06080c

Browse files
authored
Secure isLTE and isGTE functions (#2410)
1 parent 2922d3b commit d06080c

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/dateutils.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ describe('dateutils', function () {
7171
});
7272

7373
describe('isLTE()', function () {
74+
it('a is undefined', function () {
75+
const a = undefined;
76+
const b = XDate(2014, 1, 20);
77+
expect(isLTE(b, a)).toBe(undefined);
78+
});
79+
80+
it('b is undefined', function () {
81+
const a = XDate(2013, 12, 31);
82+
const b = undefined;
83+
expect(isLTE(b, a)).toBe(undefined);
84+
});
85+
86+
it('both are undefined', function () {
87+
expect(isLTE(undefined, undefined)).toBe(undefined);
88+
});
89+
7490
it('2014-01-20 >= 2013-12-31', function () {
7591
const a = XDate(2013, 12, 31);
7692
const b = XDate(2014, 1, 20);
@@ -98,6 +114,22 @@ describe('dateutils', function () {
98114
});
99115

100116
describe('isGTE()', function () {
117+
it('a is undefined', function () {
118+
const a = undefined;
119+
const b = XDate(2014, 1, 20);
120+
expect(isGTE(b, a)).toBe(undefined);
121+
});
122+
123+
it('b is undefined', function () {
124+
const a = XDate(2013, 12, 31);
125+
const b = undefined;
126+
expect(isGTE(b, a)).toBe(undefined);
127+
});
128+
129+
it('both are undefined', function () {
130+
expect(isGTE(undefined, undefined)).toBe(undefined);
131+
});
132+
101133
it('2014-01-20 >= 2013-12-31', function () {
102134
const a = XDate(2013, 12, 31);
103135
const b = XDate(2014, 1, 20);

src/dateutils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,15 @@ export function isToday(date?: XDate | string) {
7878
}
7979

8080
export function isGTE(a: XDate, b: XDate) {
81-
return b.diffDays(a) > -1;
81+
if (a && b) {
82+
return b.diffDays(a) > -1;
83+
}
8284
}
8385

8486
export function isLTE(a: XDate, b: XDate) {
85-
return a.diffDays(b) > -1;
87+
if (a && b) {
88+
return a.diffDays(b) > -1;
89+
}
8690
}
8791

8892
export function formatNumbers(date: any) {

0 commit comments

Comments
 (0)