Skip to content
This repository was archived by the owner on Aug 4, 2025. It is now read-only.

Commit 3744a46

Browse files
author
cat-bro
authored
Merge pull request #77 from uptick/fix/strict-parsing-for-month-text-input
UP-1700 Use strict parsing in Month.js handleTextChange
2 parents 9b5a9e6 + e259f41 commit 3744a46

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

src/filters/types/Month.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class Month extends React.Component {
4848
const textValue = this.refs.textInput.value
4949
let monthValue
5050
this.setState(() => ({textValue: textValue}))
51-
const parsedMonth = moment(textValue, this.props.format)
51+
// use the moment option strict=true to prevent excessive preemptive parsing
52+
const parsedMonth = moment(textValue, this.props.format, true)
5253
if (parsedMonth.isValid()) {
5354
monthValue = parsedMonth
5455
} else {

src/filters/types/__tests__/Month.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('Month', () => {
5656
value: 'Jan 2016',
5757
},
5858
}
59-
const monthValue = Moment(instance.refs.textInput.value, instance.props.format)
59+
const monthValue = Moment(instance.refs.textInput.value, instance.props.format, true) // strict=true
6060
instance.handleTextChange()
6161
expect(instance.state.textValue).toBe(instance.refs.textInput.value)
6262
expect(baseProps.onChange).toHaveBeenCalledWith(monthValue)

0 commit comments

Comments
 (0)