Skip to content

Commit e4f2cb9

Browse files
authored
fix: [1815] Removes the min and max boundary check when setting the value of an input field of type "date" (#1816)
1 parent 91e786a commit e4f2cb9

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

packages/happy-dom/src/nodes/html-input-element/HTMLInputElementValueSanitizer.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ export default class HTMLInputElementValueSanitizer {
5858
case 'date':
5959
// https://html.spec.whatwg.org/multipage/input.html#date-state-(type=date):value-sanitization-algorithm
6060
value = this.sanitizeDate(value);
61-
return value && this.checkBoundaries(value, input.min, input.max) ? value : '';
61+
return value &&
62+
this.checkBoundaries<Date>(
63+
new Date(value),
64+
input.min ? new Date(input.min) : null,
65+
input.max ? new Date(input.max) : null
66+
)
67+
? value
68+
: '';
6269
case 'datetime-local': {
6370
// https://html.spec.whatwg.org/multipage/input.html#local-date-and-time-state-(type=datetime-local):value-sanitization-algorithm
6471
const match = value.match(

packages/happy-dom/test/nodes/html-input-element/HTMLInputElementValueSanitizer.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ describe('HTMLInputElementValueSanitizer', () => {
4343
{ value: '2020-13-01', want: '' },
4444
{ value: '2020-01-1', want: '' },
4545
{ value: '2020-01-01', want: '', attributes: { min: '2020-01-02' } },
46-
{ value: '2020-01-01', want: '', attributes: { max: '2019-12-31' } }
46+
{ value: '2020-01-01', want: '', attributes: { max: '2019-12-31' } },
47+
{ value: '2020-01-02', want: '2020-01-02', attributes: { min: '2020-01-01' } },
48+
{ value: '2020-01-01', want: '2020-01-01', attributes: { max: '2020-01-02' } }
4749
],
4850
'datetime-local': [
4951
{ value: '2020-01-01T00:00', want: '2020-01-01T00:00' },

0 commit comments

Comments
 (0)