Skip to content

Commit cc01dd2

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.5
2 parents b17255a + da4861c commit cc01dd2

File tree

8 files changed

+40
-36
lines changed

8 files changed

+40
-36
lines changed

phpstan-baseline.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6356,11 +6356,6 @@
63566356
'count' => 1,
63576357
'path' => __DIR__ . '/system/HTTP/MessageInterface.php',
63586358
];
6359-
$ignoreErrors[] = [
6360-
'message' => '#^Call to function is_array\\(\\) with array will always evaluate to true\\.$#',
6361-
'count' => 1,
6362-
'path' => __DIR__ . '/system/HTTP/Negotiate.php',
6363-
];
63646359
$ignoreErrors[] = [
63656360
'message' => '#^Method CodeIgniter\\\\HTTP\\\\Negotiate\\:\\:charset\\(\\) has parameter \\$supported with no value type specified in iterable type array\\.$#',
63666361
'count' => 1,
@@ -7011,11 +7006,6 @@
70117006
'count' => 1,
70127007
'path' => __DIR__ . '/system/Helpers/filesystem_helper.php',
70137008
];
7014-
$ignoreErrors[] = [
7015-
'message' => '#^Call to function is_array\\(\\) with array will always evaluate to true\\.$#',
7016-
'count' => 1,
7017-
'path' => __DIR__ . '/system/Helpers/form_helper.php',
7018-
];
70197009
$ignoreErrors[] = [
70207010
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
70217011
'count' => 1,
@@ -7206,11 +7196,6 @@
72067196
'count' => 1,
72077197
'path' => __DIR__ . '/system/Helpers/form_helper.php',
72087198
];
7209-
$ignoreErrors[] = [
7210-
'message' => '#^Only booleans are allowed in &&, array given on the right side\\.$#',
7211-
'count' => 1,
7212-
'path' => __DIR__ . '/system/Helpers/form_helper.php',
7213-
];
72147199
$ignoreErrors[] = [
72157200
'message' => '#^Only booleans are allowed in a negated boolean, int\\<0, max\\> given\\.$#',
72167201
'count' => 1,

system/Common.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -432,22 +432,22 @@ function env(string $key, $default = null)
432432
*/
433433
function esc($data, string $context = 'html', ?string $encoding = null)
434434
{
435+
$context = strtolower($context);
436+
437+
// Provide a way to NOT escape data since
438+
// this could be called automatically by
439+
// the View library.
440+
if ($context === 'raw') {
441+
return $data;
442+
}
443+
435444
if (is_array($data)) {
436445
foreach ($data as &$value) {
437446
$value = esc($value, $context);
438447
}
439448
}
440449

441450
if (is_string($data)) {
442-
$context = strtolower($context);
443-
444-
// Provide a way to NOT escape data since
445-
// this could be called automatically by
446-
// the View library.
447-
if ($context === 'raw') {
448-
return $data;
449-
}
450-
451451
if (! in_array($context, ['html', 'js', 'css', 'url', 'attr'], true)) {
452452
throw new InvalidArgumentException('Invalid escape context provided.');
453453
}

system/HTTP/Negotiate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public function parseHeader(string $header): array
276276
protected function match(array $acceptable, string $supported, bool $enforceTypes = false, $matchLocales = false): bool
277277
{
278278
$supported = $this->parseHeader($supported);
279-
if (is_array($supported) && count($supported) === 1) {
279+
if (count($supported) === 1) {
280280
$supported = $supported[0];
281281
}
282282

system/Helpers/form_helper.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,8 @@ function form_label(string $labelText = '', string $id = '', array $attributes =
457457
$label .= ' for="' . $id . '"';
458458
}
459459

460-
if (is_array($attributes) && $attributes) {
461-
foreach ($attributes as $key => $val) {
462-
$label .= ' ' . $key . '="' . $val . '"';
463-
}
460+
foreach ($attributes as $key => $val) {
461+
$label .= ' ' . $key . '="' . $val . '"';
464462
}
465463

466464
return $label . '>' . $labelText . '</label>';

tests/system/CommonFunctionsTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,27 @@ public function testEscapeBadContextZero(): void
248248
esc('<script>', '0');
249249
}
250250

251+
public function testEscapeArray(): void
252+
{
253+
$data = [
254+
'a' => [
255+
'b' => 'c&',
256+
],
257+
'd' => 'e>',
258+
];
259+
$expected = $data;
260+
$expected['a']['b'] = 'c&amp;';
261+
$expected['d'] = 'e&gt;';
262+
$this->assertSame($expected, esc($data));
263+
}
264+
265+
public function testEscapeRecursiveArrayRaw(): void
266+
{
267+
$data = ['a' => 'b', 'c' => 'd'];
268+
$data['e'] = &$data;
269+
$this->assertSame($data, esc($data, 'raw'));
270+
}
271+
251272
/**
252273
* @runInSeparateProcess
253274
* @preserveGlobalState disabled

user_guide_src/source/concepts/factories.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,17 @@ The following code loads **app/Libraries/Sub/SubLib.php** if it exists:
8686
.. literalinclude:: factories/013.php
8787
:lines: 2-
8888

89-
Passing Full Qualified Classname
90-
--------------------------------
89+
Passing Fully Qualified Classname
90+
---------------------------------
9191

92-
You could also request a full qualified classname:
92+
You could also request a fully qualified classname:
9393

9494
.. literalinclude:: factories/002.php
9595
:lines: 2-
9696

9797
It returns the instance of ``Blog\Models\UserModel`` if it exists.
9898

99-
.. note:: Prior to v4.4.0, when you requested a full qualified classname,
99+
.. note:: Prior to v4.4.0, when you requested a fully qualified classname,
100100
if you had only ``Blog\Models\UserModel``, the instance would be returned.
101101
But if you had both ``App\Models\UserModel`` and ``Blog\Models\UserModel``,
102102
the instance of ``App\Models\UserModel`` would be returned.
@@ -143,7 +143,7 @@ the ``Factories::define()`` method:
143143

144144
The first parameter is a component. The second parameter is a class alias
145145
(the first parameter to Factories magic static method), and the third parameter
146-
is the true full qualified classname to be loaded.
146+
is the true fully qualified classname to be loaded.
147147

148148
After that, if you load ``Myth\Auth\Models\UserModel`` with Factories, the
149149
``App\Models\UserModel`` instance will be returned:

user_guide_src/source/tutorial/news_section.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Create **app/Views/news/index.php** and add the next piece of code.
176176

177177
.. literalinclude:: news_section/005.php
178178

179-
.. note:: We are again using using :php:func:`esc()` to help prevent XSS attacks.
179+
.. note:: We are again using :php:func:`esc()` to help prevent XSS attacks.
180180
But this time we also passed "url" as a second parameter. That's because
181181
attack patterns are different depending on the context in which the output
182182
is used.

user_guide_src/source/tutorial/static_pages.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ controller you made above produces...
219219
| localhost:8080/pages | the results from the ``index()`` method inside our ``Pages`` |
220220
| | controller, which is to display the CodeIgniter "welcome" page. |
221221
+---------------------------------+-----------------------------------------------------------------+
222-
| localhost:8080/home | show the "home" page that you made above, because we explicitly |
222+
| localhost:8080/home | the "home" page that you made above, because we explicitly |
223223
| | asked for it. the results from the ``view()`` method inside our |
224224
| | ``Pages`` controller. |
225225
+---------------------------------+-----------------------------------------------------------------+

0 commit comments

Comments
 (0)