Hi, I'm using "rules_data_type_date" Class to handle rules with dates objects, but the rules_data_type_date::check_value() returns a valid date even if it's input value is wrong.
The main reason rely on "rules_gmstrtotime($time)" function that, if the given $time parameter is an invalid string, it returns "1970-01-01 00:00:00".
This is caused by the unchecked return value of php strtotime() function invocation: it returns FALSE if the given time is not valid.
IMHO rules_gmstrtotime() should return NULL if the given parameter is invalid, and then rules_data_type_date::check_value() must check if NULL is returned.
Snippet from *new* rules_gmstrtotime() function
// If the time string is not in plain old date format (e.g. 'now', '+1 day'
// etc.), we need to convert it first.
$value = strtotime($time);
if ($value === FALSE)
return NULL;
$date = gmdate('Y-m-d H:i:s', $value);
return strtotime($date .' UTC');
}
Suggested *new* rules_data_type_date::check_value() implementation
function check_value($info, $value) {
if (is_numeric($value)) {
$value = gmdate('Y-m-d H:i:s', $value);
}
else if (is_string($value) && ($time = rules_gmstrtotime($value)) != NULL) {
$value = gmdate('Y-m-d H:i:s', $time);
}
if (is_string($value) && preg_match(RULES_DATE_REGEX_LOOSE, $value)) {
return $value;
}
}
Regards
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 0001-Issue-1212006-by-ThePanz-fixed-wrong-rules_gmstrtoti.patch | 1.66 KB | thepanz |
Comments
Comment #1
thepanz commentedComment #2
fagoPlease create a proper patch, see here.
Comment #3
thepanz commentedPathc attached
Comment #4
mitchell commentedComment #5
tr commentedThis code still exists in D7 Rules (but not in D8), so I'm moving the version and changing this into a feature request - it doesn't seem to have caused problems for anyone over the years ... (no other issues mention this).
The patch was for D6, so obviously doesn't apply anymore. Also, there are dpm() calls left in there that should not be in there.
If someone wants to work on this for D7, please supply a patch and preferably also a test case.