Multi-value date fields pass an array to strtotime()

Open Beginner friendly
#149 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
php
Domain
backend

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Automattic/custom-metadata

All issues in Automattic/custom-metadata

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.