-
Notifications
You must be signed in to change notification settings - Fork 770
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
RFC 3339 Z suffix no longer works with date-time validation in 2.3 #1442
Comments
Are you sure that it's working on version 2.2? I'm getting an exception when I runt the code below: v::dateTime(\DateTime::RFC3339)->assert('2014-04-12T23:20:50.052Z') |
v::dateTime(\DateTime::RFC3339)->assert('2005-12-30T01:02:03+00:00') This works fine on 2.3 |
If you use PHP's DateTime constant as a format, you must check its value. See DateTimeInterface
It is possible to validate that the way you want, but you must use a different format: I wouldn't like to overwrite PHP's default behaviour because that could cause more confusion. If I misunderstood your request, feel free to reopen the issue. I'm here to help! Cheers 🐼 |
Yes, this was working on 2.2. The tests for the above repo pass with 2.2 and fail with 2.3. We have weekly automated builds that were passing until last week. I also just tested this downgrading to 2.2.
outputs |
I bisected the issue to 5fe4b96. |
The issue is |
The DateTime::RFC3339 formats no longer work with valid RFC 3339 timestamps. See Respect/Validation#1442.
The DateTime::RFC3339 formats no longer work with valid RFC 3339 timestamps. See Respect/Validation#1442.
I wouldn't call this an "issue", although I understand that that can be problematic for your use case. The commit you mentioned aimed to fix an issue with the date-related rules. See #1274. Our date-related rules aim to respect the format that we pass to them. The value of |
This is a breaking change. It accepted valid RFC 3339 timestamps before the
change with the PHP RFC3339 format and now it rejects them.
…On Fri, Feb 2, 2024, 3:27 AM Henrique Moody ***@***.***> wrote:
I wouldn't call this an "issue", although I understand that that can be
problematic for your use case.
The commit you mentioned aimed to fix an issue with the date-related
rules. See #1274 <#1274>.
The date-related aim is to respect the format that we pass to them. The
value of DateTimeInterface::RFC3339 is Y-m-d\\TH:i:sP, while the input in
your example matches the Y-m-d\TH:i:s.vp format.
—
Reply to this email directly, view it on GitHub
<#1442 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACECMYKAIIEPK3NBV7RTB3YRTESTAVCNFSM6AAAAABCPVUGWOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRTGYYTINZQGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I understand, and I'm sorry you are frustrated because your code doesn't work as expected. After all, that happened because we changed things, not you. I insist that when you pass a format to the DateTime rule, it expects the input to match the format you pass to it. From the perspective of the rule, the value you're passing is In fact, PHP itself cannot parse all dates using that constant, even the ones mentioned in the RFC itself. See https://onlinephp.io/c/4609f Reverting that commit will defeat the purpose of our date-related rules, and I will not do that. That change makes the rules more predictable and accurate. |
I suggest you add another rule to your chain, so it will accept yet another format |
If you look at the commit that mentions this issue, I did that. However, users of my library that happen to have a newer version of How do you suggest I deal with the other cases where this breaking change caused valid timestamps to fail, e.g., fractional seconds? For instance, |
You need to include formats you intend your rule to pass. If diff --git a/src/MinFraud/Validation/Rules/Event.php b/src/MinFraud/Validation/Rules/Event.php
index ea2a33c..3639b50 100644
--- a/src/MinFraud/Validation/Rules/Event.php
+++ b/src/MinFraud/Validation/Rules/Event.php
@@ -20,7 +20,9 @@ class Event extends AbstractWrapper
'time',
v::anyOf(
v::dateTime(\DateTime::RFC3339),
- v::dateTime(\DateTime::RFC3339_EXTENDED)
+ v::dateTime(\DateTime::RFC3339_EXTENDED),
+ v::dateTime('Y-m-d\TH:i:s.vp'),
+ v::dateTime('Y-m-d\TH:i:sp'),
),
false
), |
Perhaps I didn't understand you. I saw you commit maxmind/minfraud-api-php@a23246f, and you did exactly what I did.
I understand that this may be upsetting, but the change introduced was, in fact, a bug fix. The problem was that your code used the bug in its favour, as it was more flexible. If I revert the change, there could be other people experiencing a "real" bug.
That's what I don't think I understood.
It does, and I understand that. However, neither |
I think this is confusing parsing with formatting.
Yes, like <?php
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
v::dateTime(\DateTime::RFC3339_EXTENDED)->assert('2014-04-12T23:20:50.05+00:00'); I receive the following error on 2.3:
As mentioned above, this is due to the use of the fractional second. PHP formats it as three digits, i.e., |
I see a distinction between parsing and formatting, but remember that the date-related rules validate whether the input matches a given format and NOT if the input can be parsed with The DateTime::format()'s documentation states that
If we break down the last date/time you provided,
The DateTimeImmutable::createFromFormat()'s documentation states:
I think the value of It is good that That said, I insist that this is not a bug but the expected behaviour of Validation. I will not revert the changes we made on version 2.3 Alternatively, you might use |
Hi @oschwald! It took me a while to come around, but I can see now how this is a breaking change. I might need your opinion about this, because it's been a month since I released version 2.3. I could revert this change, but that means it will also be a breaking change for people using version 2.3. Do you have any suggestions? |
Before 2.3, this code using
\DateTime::RFC3339
accepted RFC 3339 timestamps with the Zulu (Z
) suffix, e.g.,2014-04-12T23:20:50.052Z
. As of 2.3, an exception with the messagetime must be a valid date/time in the format "2005-12-30T01:02:03+00:00"
is thrown.I previously mentioned this in a comment. I probably should have created a separate issue, but I didn't think much of it after initially testing out the pre-release version.
The text was updated successfully, but these errors were encountered: