Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into 4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Mar 22, 2024
2 parents b17255a + da4861c commit cc01dd2
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 36 deletions.
15 changes: 0 additions & 15 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -6356,11 +6356,6 @@
'count' => 1,
'path' => __DIR__ . '/system/HTTP/MessageInterface.php',
];
$ignoreErrors[] = [
'message' => '#^Call to function is_array\\(\\) with array will always evaluate to true\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/HTTP/Negotiate.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\HTTP\\\\Negotiate\\:\\:charset\\(\\) has parameter \\$supported with no value type specified in iterable type array\\.$#',
'count' => 1,
Expand Down Expand Up @@ -7011,11 +7006,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Helpers/filesystem_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Call to function is_array\\(\\) with array will always evaluate to true\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Helpers/form_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 1,
Expand Down Expand Up @@ -7206,11 +7196,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Helpers/form_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in &&, array given on the right side\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Helpers/form_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a negated boolean, int\\<0, max\\> given\\.$#',
'count' => 1,
Expand Down
18 changes: 9 additions & 9 deletions system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,22 +432,22 @@ function env(string $key, $default = null)
*/
function esc($data, string $context = 'html', ?string $encoding = null)
{
$context = strtolower($context);

// Provide a way to NOT escape data since
// this could be called automatically by
// the View library.
if ($context === 'raw') {
return $data;
}

if (is_array($data)) {
foreach ($data as &$value) {
$value = esc($value, $context);
}
}

if (is_string($data)) {
$context = strtolower($context);

// Provide a way to NOT escape data since
// this could be called automatically by
// the View library.
if ($context === 'raw') {
return $data;
}

if (! in_array($context, ['html', 'js', 'css', 'url', 'attr'], true)) {
throw new InvalidArgumentException('Invalid escape context provided.');
}
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/Negotiate.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public function parseHeader(string $header): array
protected function match(array $acceptable, string $supported, bool $enforceTypes = false, $matchLocales = false): bool
{
$supported = $this->parseHeader($supported);
if (is_array($supported) && count($supported) === 1) {
if (count($supported) === 1) {
$supported = $supported[0];
}

Expand Down
6 changes: 2 additions & 4 deletions system/Helpers/form_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,8 @@ function form_label(string $labelText = '', string $id = '', array $attributes =
$label .= ' for="' . $id . '"';
}

if (is_array($attributes) && $attributes) {
foreach ($attributes as $key => $val) {
$label .= ' ' . $key . '="' . $val . '"';
}
foreach ($attributes as $key => $val) {
$label .= ' ' . $key . '="' . $val . '"';
}

return $label . '>' . $labelText . '</label>';
Expand Down
21 changes: 21 additions & 0 deletions tests/system/CommonFunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,27 @@ public function testEscapeBadContextZero(): void
esc('<script>', '0');
}

public function testEscapeArray(): void
{
$data = [
'a' => [
'b' => 'c&',
],
'd' => 'e>',
];
$expected = $data;
$expected['a']['b'] = 'c&amp;';
$expected['d'] = 'e&gt;';
$this->assertSame($expected, esc($data));
}

public function testEscapeRecursiveArrayRaw(): void
{
$data = ['a' => 'b', 'c' => 'd'];
$data['e'] = &$data;
$this->assertSame($data, esc($data, 'raw'));
}

/**
* @runInSeparateProcess
* @preserveGlobalState disabled
Expand Down
10 changes: 5 additions & 5 deletions user_guide_src/source/concepts/factories.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ The following code loads **app/Libraries/Sub/SubLib.php** if it exists:
.. literalinclude:: factories/013.php
:lines: 2-

Passing Full Qualified Classname
--------------------------------
Passing Fully Qualified Classname
---------------------------------

You could also request a full qualified classname:
You could also request a fully qualified classname:

.. literalinclude:: factories/002.php
:lines: 2-

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

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

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

After that, if you load ``Myth\Auth\Models\UserModel`` with Factories, the
``App\Models\UserModel`` instance will be returned:
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/tutorial/news_section.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Create **app/Views/news/index.php** and add the next piece of code.

.. literalinclude:: news_section/005.php

.. note:: We are again using using :php:func:`esc()` to help prevent XSS attacks.
.. note:: We are again using :php:func:`esc()` to help prevent XSS attacks.
But this time we also passed "url" as a second parameter. That's because
attack patterns are different depending on the context in which the output
is used.
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/tutorial/static_pages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ controller you made above produces...
| localhost:8080/pages | the results from the ``index()`` method inside our ``Pages`` |
| | controller, which is to display the CodeIgniter "welcome" page. |
+---------------------------------+-----------------------------------------------------------------+
| localhost:8080/home | show the "home" page that you made above, because we explicitly |
| localhost:8080/home | the "home" page that you made above, because we explicitly |
| | asked for it. the results from the ``view()`` method inside our |
| | ``Pages`` controller. |
+---------------------------------+-----------------------------------------------------------------+
Expand Down

0 comments on commit cc01dd2

Please sign in to comment.