Skip to content

Commit b85da0e

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.3
2 parents ff7e096 + 12e2a8d commit b85da0e

File tree

9 files changed

+220
-37
lines changed

9 files changed

+220
-37
lines changed

system/Helpers/url_helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ function _get_uri(string $relativePath = '', ?App $config = null): URI
7474
/**
7575
* Returns a site URL as defined by the App config.
7676
*
77-
* @param mixed $relativePath URI string or array of URI segments
78-
* @param App|null $config Alternate configuration to use
77+
* @param array|string $relativePath URI string or array of URI segments
78+
* @param App|null $config Alternate configuration to use
7979
*/
8080
function site_url($relativePath = '', ?string $scheme = null, ?App $config = null): string
8181
{

system/Log/Handlers/ChromeLoggerHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ public function sendLogs(?ResponseInterface &$response = null)
157157
$response = Services::response(null, true);
158158
}
159159

160-
$data = base64_encode(utf8_encode(json_encode($this->json)));
160+
$data = base64_encode(
161+
mb_convert_encoding(json_encode($this->json), 'UTF-8', mb_list_encodings())
162+
);
161163

162164
$response->setHeader($this->header, $data);
163165
}

system/View/Filters.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static function capitalize(string $value): string
3030
/**
3131
* Formats a date into the given $format.
3232
*
33-
* @param mixed $value
33+
* @param int|string|null $value
3434
*/
3535
public static function date($value, string $format): string
3636
{
@@ -48,7 +48,7 @@ public static function date($value, string $format): string
4848
* Example:
4949
* my_date|date_modify(+1 day)
5050
*
51-
* @param string $value
51+
* @param int|string|null $value
5252
*
5353
* @return false|int
5454
*/
@@ -62,7 +62,7 @@ public static function date_modify($value, string $adjustment)
6262
/**
6363
* Returns the given default value if $value is empty or undefined.
6464
*
65-
* @param mixed $value
65+
* @param array|bool|float|int|object|resource|string|null $value
6666
*/
6767
public static function default($value, string $default): string
6868
{
@@ -208,15 +208,18 @@ public static function prose(string $value): string
208208
* - ceil always rounds up
209209
* - floor always rounds down
210210
*
211-
* @param mixed $precision
211+
* @param int|string $precision precision or type
212212
*
213213
* @return float|string
214214
*/
215215
public static function round(string $value, $precision = 2, string $type = 'common')
216216
{
217+
// In case that $precision is a type like `{ value1|round(ceil) }`
217218
if (! is_numeric($precision)) {
218219
$type = $precision;
219220
$precision = 2;
221+
} else {
222+
$precision = (int) $precision;
220223
}
221224

222225
switch ($type) {

system/View/Parser.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace CodeIgniter\View;
1313

14+
use CodeIgniter\Autoloader\FileLocator;
1415
use CodeIgniter\View\Exceptions\ViewException;
1516
use Config\View as ViewConfig;
1617
use ParseError;
@@ -72,10 +73,7 @@ class Parser extends View
7273
/**
7374
* Constructor
7475
*
75-
* @param string $viewPath
76-
* @param mixed $loader
77-
* @param bool $debug
78-
* @param LoggerInterface $logger
76+
* @param FileLocator|null $loader
7977
*/
8078
public function __construct(ViewConfig $config, ?string $viewPath = null, $loader = null, ?bool $debug = null, ?LoggerInterface $logger = null)
8179
{
@@ -90,9 +88,6 @@ public function __construct(ViewConfig $config, ?string $viewPath = null, $loade
9088
*
9189
* Parses pseudo-variables contained in the specified template view,
9290
* replacing them with any data that has already been set.
93-
*
94-
* @param array $options
95-
* @param bool $saveData
9691
*/
9792
public function render(string $view, ?array $options = null, ?bool $saveData = null): string
9893
{
@@ -153,9 +148,6 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n
153148
*
154149
* Parses pseudo-variables contained in the specified string,
155150
* replacing them with any data that has already been set.
156-
*
157-
* @param array $options
158-
* @param bool $saveData
159151
*/
160152
public function renderString(string $template, ?array $options = null, ?bool $saveData = null): string
161153
{
@@ -187,8 +179,8 @@ public function renderString(string $template, ?array $options = null, ?bool $sa
187179
* so that the variable is correctly handled within the
188180
* parsing itself, and contexts (including raw) are respected.
189181
*
190-
* @param string $context The context to escape it for: html, css, js, url, raw
191-
* If 'raw', no escaping will happen
182+
* @param string|null $context The context to escape it for: html, css, js, url, raw
183+
* If 'raw', no escaping will happen
192184
*/
193185
public function setData(array $data = [], ?string $context = null): RendererInterface
194186
{
@@ -503,9 +495,9 @@ public function setConditionalDelimiters($leftDelimiter = '{', $rightDelimiter =
503495
* Handles replacing a pseudo-variable with the actual content. Will double-check
504496
* for escaping brackets.
505497
*
506-
* @param mixed $pattern
507-
* @param string $content
508-
* @param string $template
498+
* @param array|string $pattern
499+
* @param string $content
500+
* @param string $template
509501
*/
510502
protected function replaceSingle($pattern, $content, $template, bool $escape = false): string
511503
{
@@ -698,9 +690,9 @@ public function removePlugin(string $alias)
698690
* Converts an object to an array, respecting any
699691
* toArray() methods on an object.
700692
*
701-
* @param mixed $value
693+
* @param array|bool|float|int|object|string|null $value
702694
*
703-
* @return mixed
695+
* @return array|bool|float|int|string|null
704696
*/
705697
protected function objectToArray($value)
706698
{

tests/system/Helpers/URLHelper/SiteUrlTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,16 @@ public function testUrls($baseURL, $indexPage, $scheme, $secure, $path, $expecte
7777

7878
public function configProvider()
7979
{
80-
// baseURL, indexPage, scheme, path, expectedSiteUrl
80+
// baseURL, indexPage, scheme, secure, path, expectedSiteUrl
8181
return [
82+
'forceGlobalSecure' => [
83+
'http://example.com/',
84+
'index.php',
85+
null,
86+
true,
87+
'',
88+
'https://example.com/index.php',
89+
],
8290
[
8391
'http://example.com/',
8492
'index.php',
@@ -119,6 +127,22 @@ public function configProvider()
119127
'abc',
120128
'http://example.com/abc',
121129
],
130+
'URL decode' => [
131+
'http://example.com/',
132+
'',
133+
null,
134+
false,
135+
'template/meet-%26-greet',
136+
'http://example.com/template/meet-&-greet',
137+
],
138+
'URL encode' => [
139+
'http://example.com/',
140+
'',
141+
null,
142+
false,
143+
'<s>alert</s>',
144+
'http://example.com/%3Cs%3Ealert%3C/s%3E',
145+
],
122146
[
123147
'http://example.com/public/',
124148
'index.php',

tests/system/Validation/RulesTest.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,4 +639,97 @@ public function requiredWithoutProvider(): Generator
639639
],
640640
];
641641
}
642+
643+
/**
644+
* @dataProvider requiredWithoutMultipleProvider
645+
*/
646+
public function testRequiredWithoutMultiple(string $foo, string $bar, string $baz, bool $result): void
647+
{
648+
$this->validation->setRules(['foo' => 'required_without[bar,baz]']);
649+
650+
$data = [
651+
'foo' => $foo,
652+
'bar' => $bar,
653+
'baz' => $baz,
654+
];
655+
$this->assertSame($result, $this->validation->run($data));
656+
}
657+
658+
public function requiredWithoutMultipleProvider(): Generator
659+
{
660+
yield from [
661+
'all empty' => [
662+
'',
663+
'',
664+
'',
665+
false,
666+
],
667+
'foo is not empty' => [
668+
'a',
669+
'',
670+
'',
671+
true,
672+
],
673+
'bar is not empty' => [
674+
'',
675+
'b',
676+
'',
677+
false,
678+
],
679+
'baz is not empty' => [
680+
'',
681+
'',
682+
'c',
683+
false,
684+
],
685+
'bar,baz are not empty' => [
686+
'',
687+
'b',
688+
'c',
689+
true,
690+
],
691+
];
692+
}
693+
694+
/**
695+
* @dataProvider requiredWithoutMultipleWithoutFieldsProvider
696+
*/
697+
public function testRequiredWithoutMultipleWithoutFields(array $data, bool $result): void
698+
{
699+
$this->validation->setRules(['foo' => 'required_without[bar,baz]']);
700+
701+
$this->assertSame($result, $this->validation->run($data));
702+
}
703+
704+
public function requiredWithoutMultipleWithoutFieldsProvider(): Generator
705+
{
706+
yield from [
707+
'baz is missing' => [
708+
[
709+
'foo' => '',
710+
'bar' => '',
711+
],
712+
false,
713+
],
714+
'bar,baz are missing' => [
715+
[
716+
'foo' => '',
717+
],
718+
false,
719+
],
720+
'bar is not empty' => [
721+
[
722+
'foo' => '',
723+
'bar' => 'b',
724+
],
725+
false,
726+
],
727+
'foo is not empty' => [
728+
[
729+
'foo' => 'a',
730+
],
731+
true,
732+
],
733+
];
734+
}
642735
}

tests/system/View/ParserFilterTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,15 @@ public function testRound()
270270
$parser = new Parser($this->config, $this->viewsDir, $this->loader);
271271

272272
$data = [
273-
'value1' => 5.55,
273+
'value1' => 5.555,
274274
];
275275

276-
$template = '{ value1|round(1) } { value1|round(1, common) } { value1|round(ceil) } { value1|round(floor) } { value1|round(unknown) }';
276+
$template = '{ value1|round(1) } / { value1|round(1, common) }'
277+
. ' / { value1|round(ceil) } / { value1|round(floor) }'
278+
. ' / { value1|round(unknown) }';
277279

278280
$parser->setData($data);
279-
$this->assertSame('5.6 5.6 6 5 5.55', $parser->renderString($template));
281+
$this->assertSame('5.6 / 5.6 / 6 / 5 / 5.555', $parser->renderString($template));
280282
}
281283

282284
public function testStripTags()

tests/system/View/ParserTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,71 @@ public function testParseLoopObjectProperties()
265265
$this->assertSame("Super Heroes\nTom Dick Henry ", $this->parser->renderString($template));
266266
}
267267

268+
public function testParseIntegerPositive()
269+
{
270+
$data = [
271+
'title' => 'Count:',
272+
'amount' => 5,
273+
];
274+
275+
$template = '{title} {amount}';
276+
277+
$this->parser->setData($data, 'html');
278+
$this->assertSame('Count: 5', $this->parser->renderString($template));
279+
}
280+
281+
public function testParseIntegerNegative()
282+
{
283+
$data = [
284+
'title' => 'Count:',
285+
'amount' => -5,
286+
];
287+
288+
$template = '{title} {amount}';
289+
290+
$this->parser->setData($data, 'html');
291+
$this->assertSame('Count: -5', $this->parser->renderString($template));
292+
}
293+
294+
public function testParseFloatPositive()
295+
{
296+
$data = [
297+
'title' => 'Rate:',
298+
'amount' => 5.5,
299+
];
300+
301+
$template = '{title} {amount}';
302+
303+
$this->parser->setData($data, 'html');
304+
$this->assertSame('Rate: 5.5', $this->parser->renderString($template));
305+
}
306+
307+
public function testParseFloatNegative()
308+
{
309+
$data = [
310+
'title' => 'Rate:',
311+
'amount' => -5.5,
312+
];
313+
314+
$template = '{title} {amount}';
315+
316+
$this->parser->setData($data, 'html');
317+
$this->assertSame('Rate: -5.5', $this->parser->renderString($template));
318+
}
319+
320+
public function testParseNull()
321+
{
322+
$data = [
323+
'title' => 'Ticks:',
324+
'amount' => null,
325+
];
326+
327+
$template = '{title} {amount}';
328+
329+
$this->parser->setData($data, 'html');
330+
$this->assertSame('Ticks: ', $this->parser->renderString($template));
331+
}
332+
268333
public function testParseLoopEntityProperties()
269334
{
270335
$power = new class () extends Entity {

0 commit comments

Comments
 (0)