Skip to content
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

Fix Implicit conversion from float <number> to int loses precision #1

Closed
wants to merge 1 commit into from
Closed

Fix Implicit conversion from float <number> to int loses precision #1

wants to merge 1 commit into from

Conversation

brian978
Copy link
Contributor

No description provided.

@symfony-bot
Copy link

symfony-bot bot commented Jan 19, 2022

Thanks for your pull request! We love contributions.

However, this repository is what we call a "subtree split": a read-only copy of one directory of the main Symfony repository. It is used by Composer to allow developers to depend on specific Symfony components.

If you want to contribute, you should instead open a pull request on the main repository:

https://github.com/symfony/symfony

Thank you for your contribution!

PS: if you haven't already, please add tests, and beware that bug fixes should be submitted on the lowest maintained branch where they apply.

@brian978 brian978 closed this Jan 19, 2022
@brian978 brian978 deleted the bugfix/number_deprecation_notice branch January 19, 2022 06:56
symfony-splitter pushed a commit that referenced this pull request Jan 24, 2022
This PR was merged into the 5.4 branch.

Discussion
----------

[RateLimiter] Resolve crash on near-round timestamps

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Occasionally timestamps will be fully round (eg. 1234567890.000000) or close to it (eg. 1234567890.000031).

When converting those specific float timestamps to string in SlidingWindow (due to `DateTimeImmutable::createFromFormat`), the number is formatted by PHP without any digits. This causes the resulting value of SlidingWindow::getRetryAfter() to be violated with the boolean value `false`.

This patch formats the float to include the decimal digits.

```
Return value of Symfony\Component\RateLimiter\Policy\SlidingWindow::getRetryAfter() must be an instance of DateTimeImmutable, bool returned
#0 .../vendor/symfony/rate-limiter/Policy/SlidingWindowLimiter.php(84): Symfony\Component\RateLimiter\Policy\SlidingWindow->getRetryAfter()
#1 .../usercode.php(123): Symfony\Component\RateLimiter\Policy\SlidingWindowLimiter->consume(1)
```

Commits
-------

496595270d [RateLimiter] Resolve crash on near-round timestamps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant