Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5b56d4e

Browse filesBrowse files
committed
bug #45764 [RateLimiter] Fix rate serialization for long intervals (monthly and yearly) (smelesh)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [RateLimiter] Fix rate serialization for long intervals (monthly and yearly) | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #... | License | MIT | Doc PR | no Long rate intervals (monthly and yearly) are serialized with incorrect ISO interval, so token bucket refills earlier than expected: - yearly interval acts as 100 days; - monthly interval acts as 10 days. Commits ------- 4810066 [RateLimiter] Fix rate serialization for long intervals (monthly and yearly)
2 parents 5b46cb9 + 4810066 commit 5b56d4e
Copy full SHA for 5b56d4e

File tree

2 files changed

+38
-1
lines changed
Filter options

2 files changed

+38
-1
lines changed

‎src/Symfony/Component/RateLimiter/Policy/Rate.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/RateLimiter/Policy/Rate.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,6 @@ public function calculateNewTokensDuringInterval(float $duration): int
101101

102102
public function __toString(): string
103103
{
104-
return $this->refillTime->format('P%y%m%dDT%HH%iM%sS').'-'.$this->refillAmount;
104+
return $this->refillTime->format('P%yY%mM%dDT%HH%iM%sS').'-'.$this->refillAmount;
105105
}
106106
}
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\RateLimiter\Tests\Policy;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\RateLimiter\Policy\Rate;
16+
17+
class RateTest extends TestCase
18+
{
19+
/**
20+
* @dataProvider provideRate
21+
*/
22+
public function testFromString(Rate $rate)
23+
{
24+
$this->assertEquals($rate, Rate::fromString((string) $rate));
25+
}
26+
27+
public function provideRate(): iterable
28+
{
29+
yield [new Rate(\DateInterval::createFromDateString('15 seconds'), 10)];
30+
yield [Rate::perSecond(10)];
31+
yield [Rate::perMinute(10)];
32+
yield [Rate::perHour(10)];
33+
yield [Rate::perDay(10)];
34+
yield [Rate::perMonth(10)];
35+
yield [Rate::perYear(10)];
36+
}
37+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.