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

[7.x] Fixed increment bug that changes expiration to forever #32875

Merged
merged 1 commit into from
May 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fixed increment bug that changes expiration to forever
A bug was introduced recently when changing:

```
if ($existing = $this->get($key)) {
```

to

```
if (! isset($this->storage[$key])) {
```

When attempting to increment a value that starts from zero (0), before it worked correctly in that it was simply returning true in that a value was set. However, now when `$this->get($key)` returns 0 since we are incrementing from 0, it evaluates as false and thus changes expiration to "forever". This causes issues for testing rate limiting because nothing ever "expires".
  • Loading branch information
brianwozeniak authored May 18, 2020
commit 52573c74ad5561cdd62ce7701a0ba57040c1f50c
2 changes: 1 addition & 1 deletion src/Illuminate/Cache/ArrayStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function put($key, $value, $seconds)
*/
public function increment($key, $value = 1)
{
if ($existing = $this->get($key)) {
if (! is_null($existing = $this->get($key))) {
return tap(((int) $existing) + $value, function ($incremented) use ($key) {
$value = $this->serializesValues ? serialize($incremented) : $incremented;

Expand Down