-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate that a meta_value is a recognizable date value before storing #1703
Conversation
…In turn, only store date, datetime, time values if they are meaningful
@tlovett1 this is ready for review |
@moraleida were you able to reproduce the reported bug in fixing this? |
@tlovett1 I'm able to reproduce the same results in storage, but none of the indexing errors. That may or may not be related to versions/settings in the ES cluster. See the results below: these were stored using simple custom_fields in WP 5.3.2 and ElasticPress
If we want to me more strict about dates we would have to make decisions around which dates EP will consider valid. |
Do we know what dates Elasticsearch considers invalid? |
@moraleida in theory this looks good. My only thought is currently we are storing some default values even if |
@tlovett1 this is ready for testing again. The default dates are back and will be used whenever the |
a35ae35
to
636fa22
Compare
636fa22
to
b7d875e
Compare
Hi @moraleida . I pushed some commits to your branch to update the tests and make some changes. Looking at the code, only meta values that are string are checked and have cc: @brandwaffle |
Hi @Rahmon can you let me know how were you testing? I did the following: 1.- Install ACF
Shouldn't this solve #1556 (comment) ? I want to make sure I am testing correctly. |
@oscarssanchez I've tested in a similar way. The PR tests if a date is valid here Regarding #1556 (comment), I've tested and the date and datetime were not rejected by Elasticsearch (5.6). |
Thanks @Rahmon , Indeed, It looks like this should be correct as the Datetime is defined to start with the year: https://github.com/10up/ElasticPress/pull/1703/files#diff-f5aaa70470d85e353af0ee1d50c73f04d65e2c2a78336a7ac660ead2d8e61d27R477 This is looking good to me! |
Description of the Change
Introduce proper date validation for strings added to post-meta. Right now, any string passed in as a meta value to a Post, User or Term is first converted to a timestamp and then manipulated to store
date
,datetime
andtime
values.This change strenghtens the logic around that check by moving from a simple
strtotime
conversion to creating a properDateTime
object. If PHP is able to initialize aDateTime
object from$meta_value
, then we know the manipulations will be successful. If not, catch the Exception thrown and move on, as this is not a valid date.Cherry on the top, we move away from doing timezone calculations for each value, as we initialize the object with the correct timezone. This will save us some microseconds in processing.
Fixes #1556
Verification Process
This was tested by saving custom fields with values matching PHP Supported Date and Time Formats and verifying that all valid formats got properly processed in Elasticsearch, receiving the
date
,datetime
andtime
keys, as opposed to invalid formats, which were saved as simple strings ( gettingvalue
andraw
fields only ).Checklist:
Applicable Issues
Changelog Entry