Multi-value date fields pass an array to strtotime()
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
Research direction
Start in _sanitize_field_value() and trace how the date field types datepicker, datetimepicker, and timepicker handle values when multiple is true. Reproduce the array passed to strtotime(), then verify that repeatable date values are handled without warnings or data loss; choose between per-element conversion and explicitly disallowing multiple date fields.
Written by the indexing model from the issue text.
Description
Bug
In _sanitize_field_value(), the date field types (datepicker, datetimepicker, timepicker) run strtotime( $value ), which assumes $value is a scalar.
Date types are not listed in _cloneable_field_types or _field_types_that_support_multifield, but a field can still be made repeatable by passing 'multiple' => true (the render path keys "cloneable" off $field->multiple directly). In that case $value is an array, strtotime() receives an array, and it returns false / warns — corrupting the stored value.
Fix options
Either map strtotime() over each element when $value is an array, or explicitly disallow multiple on date field types. This is an edge case and low priority, but it is a latent data-loss bug worth closing off.
History
Originally raised in #113 by @tmtrademark (2014). That PR also reordered the sanitize_callback so it runs before date conversion — a separate behaviour change to weigh on its own merits. The PR no longer applies cleanly, so it is being closed in favour of this issue, which captures the array-handling fix.
- Dominant language
- PHP
- Stars
- 190
- Forks
- 46
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Automattic/custom-metadata
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Automattic/custom-metadata#148 ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 55/100
Automattic/custom-metadata#156 ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 50/100
Automattic/custom-metadata#154 ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Automattic/custom-metadata#153 ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 55/100
Automattic/custom-metadata#152 ·
All issues in Automattic/custom-metadata
Similar issues
-
priority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/librarian#7636 ·
-
0. Needs triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nextcloud/fulltextsearch#1011 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
phpstan/phpstan-doctrine#794 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Automattic/static-site-importer#1767 ·