Skip to content

Commit 7c610bf

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.3
2 parents 428057a + 924b3c4 commit 7c610bf

File tree

10 files changed

+96
-17
lines changed

10 files changed

+96
-17
lines changed

system/Cache/Handlers/RedisHandler.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,15 @@ public function increment(string $key, int $offset = 1)
200200
{
201201
$key = static::validateKey($key, $this->prefix);
202202

203-
return $this->redis->hIncrBy($key, 'data', $offset);
203+
return $this->redis->hIncrBy($key, '__ci_value', $offset);
204204
}
205205

206206
/**
207207
* {@inheritDoc}
208208
*/
209209
public function decrement(string $key, int $offset = 1)
210210
{
211-
$key = static::validateKey($key, $this->prefix);
212-
213-
return $this->redis->hIncrBy($key, 'data', -$offset);
211+
return $this->increment($key, -$offset);
214212
}
215213

216214
/**

system/Cookie/CloneableCookieInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public function withExpired();
6060
* Creates a new Cookie that will virtually never expire from the browser.
6161
*
6262
* @return static
63+
*
64+
* @deprecated See https://github.com/codeigniter4/CodeIgniter4/pull/6413
6365
*/
6466
public function withNeverExpiring();
6567

system/Cookie/Cookie.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ public function withExpired()
460460
}
461461

462462
/**
463-
* {@inheritDoc}
463+
* @deprecated See https://github.com/codeigniter4/CodeIgniter4/pull/6413
464464
*/
465465
public function withNeverExpiring()
466466
{

system/Debug/Exceptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function shutdownHandler()
179179
['type' => $type, 'message' => $message, 'file' => $file, 'line' => $line] = $error;
180180

181181
if (in_array($type, [E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE], true)) {
182-
$this->exceptionHandler(new ErrorException($message, $type, 0, $file, $line));
182+
$this->exceptionHandler(new ErrorException($message, 0, $type, $file, $line));
183183
}
184184
}
185185

system/Validation/Validation.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,9 @@ protected function processRules(
322322
if ($passed === false) {
323323
// if the $value is an array, convert it to as string representation
324324
if (is_array($value)) {
325-
$value = '[' . implode(', ', $value) . ']';
325+
$value = $this->isStringList($value)
326+
? '[' . implode(', ', $value) . ']'
327+
: json_encode($value);
326328
} elseif (is_object($value)) {
327329
$value = json_encode($value);
328330
}
@@ -345,6 +347,32 @@ protected function processRules(
345347
return true;
346348
}
347349

350+
/**
351+
* Is the array a string list `list<string>`?
352+
*/
353+
private function isStringList(array $array): bool
354+
{
355+
$expectedKey = 0;
356+
357+
foreach ($array as $key => $val) {
358+
// Note: also covers PHP array key conversion, e.g. '5' and 5.1 both become 5
359+
if (! is_int($key)) {
360+
return false;
361+
}
362+
363+
if ($key !== $expectedKey) {
364+
return false;
365+
}
366+
$expectedKey++;
367+
368+
if (! is_string($val)) {
369+
return false;
370+
}
371+
}
372+
373+
return true;
374+
}
375+
348376
/**
349377
* Takes a Request object and grabs the input data to use from its
350378
* array values.

tests/_support/Validation/TestRules.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ public function check_object_rule(object $value, ?string $fields, array $data =
3232

3333
return $find;
3434
}
35+
36+
public function array_count($value, $count): bool
37+
{
38+
return is_array($value) && count($value) === (int) $count;
39+
}
3540
}

tests/system/Cache/Handlers/RedisHandlerTest.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,22 @@ public function testDeleteMatchingSuffix()
166166
$this->assertSame('keys=90', $dbInfo[0]);
167167
}
168168

169-
// FIXME: I don't like all Hash logic very much. It's wasting memory.
170-
// public function testIncrement()
171-
// {
172-
// }
173-
174-
// public function testDecrement()
175-
// {
176-
// }
169+
public function testIncrementAndDecrement()
170+
{
171+
$this->handler->save('counter', 100);
172+
173+
foreach (range(1, 10) as $step) {
174+
$this->handler->increment('counter', $step);
175+
}
176+
177+
$this->assertSame(155, $this->handler->get('counter'));
178+
179+
$this->handler->decrement('counter', 20);
180+
$this->assertSame(135, $this->handler->get('counter'));
181+
182+
$this->handler->increment('counter', 5);
183+
$this->assertSame(140, $this->handler->get('counter'));
184+
}
177185

178186
public function testClean()
179187
{

tests/system/Validation/ValidationTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,42 @@ public function testJsonInput(): void
641641
unset($_SERVER['CONTENT_TYPE']);
642642
}
643643

644+
/**
645+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/6466
646+
*/
647+
public function testJsonInputObjectArray(): void
648+
{
649+
$json = <<<'EOL'
650+
{
651+
"p": [
652+
{
653+
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
654+
}
655+
]
656+
}
657+
EOL;
658+
659+
$_SERVER['CONTENT_TYPE'] = 'application/json';
660+
661+
$config = new App();
662+
$config->baseURL = 'http://example.com/';
663+
664+
$request = new IncomingRequest($config, new URI(), $json, new UserAgent());
665+
666+
$rules = [
667+
'p' => 'required|array_count[2]',
668+
];
669+
$validated = $this->validation
670+
->withRequest($request->withMethod('patch'))
671+
->setRules($rules)
672+
->run();
673+
674+
$this->assertFalse($validated);
675+
$this->assertSame(['p' => 'Validation.array_count'], $this->validation->getErrors());
676+
677+
unset($_SERVER['CONTENT_TYPE']);
678+
}
679+
644680
public function testHasRule(): void
645681
{
646682
$this->validation->setRuleGroup('groupA');

user_guide_src/source/changelogs/v4.2.6.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ none.
2727
Deprecations
2828
************
2929

30-
none.
30+
- :php:meth:`CodeIgniter\\Cookie\\Cookie::withNeverExpiring()` is deprecated.
3131

3232
Bugs Fixed
3333
**********

user_guide_src/source/libraries/cookies.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ In runtime, you can manually supply a new default using the ``Cookie::setDefault
223223
Class Reference
224224
***************
225225

226-
.. php:namespace:: CodeIgniter\HTTP\Cookie
226+
.. php:namespace:: CodeIgniter\Cookie
227227
228228
.. php:class:: Cookie
229229
@@ -326,6 +326,8 @@ Class Reference
326326

327327
.. php:method:: withNeverExpiring()
328328
329+
.. important:: This method is deprecated.
330+
329331
:param string $name:
330332
:rtype: ``Cookie``
331333
:returns: new ``Cookie`` instance

0 commit comments

Comments
 (0)