Skip to content

Commit 26aece4

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.3
2 parents 18ae8db + 7439b6e commit 26aece4

File tree

7 files changed

+59
-16
lines changed

7 files changed

+59
-16
lines changed

system/BaseModel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,8 @@ public function errors(bool $forceDB = false)
11461146
*/
11471147
public function paginate(?int $perPage = null, string $group = 'default', ?int $page = null, int $segment = 0)
11481148
{
1149-
$pager = Services::pager(null, null, false);
1149+
// Since multiple models may use the Pager, the Pager must be shared.
1150+
$pager = Services::pager();
11501151

11511152
if ($segment) {
11521153
$pager->setSegment($segment, $group);

system/Commands/Database/ShowTableInfo.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public function run(array $params)
129129
$tables,
130130
'required'
131131
);
132+
CLI::newLine();
132133

133134
$tableName = $tables[$tableNameNo];
134135
}
@@ -154,7 +155,6 @@ private function restoreDBPrefix(): void
154155

155156
private function showDataOfTable(string $tableName, int $limitRows, int $limitFieldValue)
156157
{
157-
CLI::newLine();
158158
CLI::write("Data of Table \"{$tableName}\":", 'black', 'yellow');
159159
CLI::newLine();
160160

@@ -245,7 +245,6 @@ private function makeTableRows(
245245

246246
private function showFieldMetaData(string $tableName): void
247247
{
248-
CLI::newLine();
249248
CLI::write("List of Metadata Information in Table \"{$tableName}\":", 'black', 'yellow');
250249
CLI::newLine();
251250

system/Config/Services.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
use Config\Toolbar as ToolbarConfig;
7676
use Config\Validation as ValidationConfig;
7777
use Config\View as ViewConfig;
78+
use Locale;
7879

7980
/**
8081
* Services Configuration file.
@@ -363,8 +364,14 @@ public static function language(?string $locale = null, bool $getShared = true)
363364
return static::getSharedInstance('language', $locale)->setLocale($locale);
364365
}
365366

367+
if (AppServices::request() instanceof IncomingRequest) {
368+
$requestLocale = AppServices::request()->getLocale();
369+
} else {
370+
$requestLocale = Locale::getDefault();
371+
}
372+
366373
// Use '?:' for empty string check
367-
$locale = $locale ?: AppServices::request()->getLocale();
374+
$locale = $locale ?: $requestLocale;
368375

369376
return new Language($locale);
370377
}

system/HTTP/ContentSecurityPolicy.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ protected function buildHeaders(ResponseInterface $response)
776776
protected function addToHeader(string $name, $values = null)
777777
{
778778
if (is_string($values)) {
779-
$values = [$values => 0];
779+
$values = [$values => $this->reportOnly];
780780
}
781781

782782
$sources = [];
@@ -785,13 +785,15 @@ protected function addToHeader(string $name, $values = null)
785785
foreach ($values as $value => $reportOnly) {
786786
if (is_numeric($value) && is_string($reportOnly) && ! empty($reportOnly)) {
787787
$value = $reportOnly;
788-
$reportOnly = 0;
788+
$reportOnly = $this->reportOnly;
789+
}
790+
791+
if (strpos($value, 'nonce-') === 0) {
792+
$value = "'{$value}'";
789793
}
790794

791795
if ($reportOnly === true) {
792796
$reportSources[] = in_array($value, $this->validSources, true) ? "'{$value}'" : $value;
793-
} elseif (strpos($value, 'nonce-') === 0) {
794-
$sources[] = "'{$value}'";
795797
} else {
796798
$sources[] = in_array($value, $this->validSources, true) ? "'{$value}'" : $value;
797799
}

tests/system/CommonFunctionsTest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ final class CommonFunctionsTest extends CIUnitTestCase
5050
protected function setUp(): void
5151
{
5252
unset($_ENV['foo'], $_SERVER['foo']);
53-
Services::reset();
53+
$this->resetServices();
5454

5555
parent::setUp();
5656
}
@@ -593,8 +593,6 @@ public function testTraceWithCSP()
593593

594594
public function testCspStyleNonce()
595595
{
596-
$this->resetServices();
597-
598596
$config = config('App');
599597
$config->CSPEnabled = true;
600598

@@ -603,11 +601,20 @@ public function testCspStyleNonce()
603601

604602
public function testCspScriptNonce()
605603
{
606-
$this->resetServices();
607-
608604
$config = config('App');
609605
$config->CSPEnabled = true;
610606

611607
$this->assertStringStartsWith('nonce="', csp_script_nonce());
612608
}
609+
610+
public function testLangOnCLI()
611+
{
612+
Services::createRequest(new App(), true);
613+
614+
$message = lang('CLI.generator.fileCreate', ['TestController.php']);
615+
616+
$this->assertSame('File created: TestController.php', $message);
617+
618+
$this->resetServices();
619+
}
613620
}

tests/system/HTTP/ContentSecurityPolicyTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function testConnectSrc()
132132
$result = $this->work();
133133

134134
$result = $this->getHeaderEmitted('Content-Security-Policy-Report-Only');
135-
$this->assertStringContainsString('connect-src iffy.com maybe.com;', $result);
135+
$this->assertStringContainsString("connect-src 'self' iffy.com maybe.com;", $result);
136136
}
137137

138138
/**
@@ -165,9 +165,10 @@ public function testFormAction()
165165
$result = $this->work();
166166

167167
$result = $this->getHeaderEmitted('Content-Security-Policy-Report-Only');
168-
$this->assertStringContainsString('form-action surveysrus.com;', $result);
168+
$this->assertStringContainsString("form-action 'self' surveysrus.com;", $result);
169+
169170
$result = $this->getHeaderEmitted('Content-Security-Policy');
170-
$this->assertStringContainsString("form-action 'self';", $result);
171+
$this->assertStringNotContainsString("form-action 'self';", $result);
171172
}
172173

173174
/**

tests/system/Models/PaginateModelTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,30 @@ public function testPaginatePageOutOfRange(): void
7979
$this->model->paginate(1, 'default', 500);
8080
$this->assertSame($this->model->pager->getPageCount(), $this->model->pager->getCurrentPage());
8181
}
82+
83+
public function testMultiplePager(): void
84+
{
85+
$_GET = [];
86+
87+
$validModel = $this->createModel(ValidModel::class);
88+
$userModel = $this->createModel(UserModel::class);
89+
90+
$validModel->paginate(1, 'valid');
91+
$userModel->paginate(1, 'user');
92+
$pager = $this->model->pager;
93+
94+
$this->assertSame($userModel->pager, $validModel->pager);
95+
96+
$this->assertSame(4, $validModel->countAllResults());
97+
$this->assertSame(4, $userModel->countAllResults());
98+
99+
$this->assertStringContainsString('?page_valid=1"', $pager->links('valid'));
100+
$this->assertStringContainsString('?page_valid=2"', $pager->links('valid'));
101+
$this->assertStringContainsString('?page_valid=3"', $pager->links('valid'));
102+
$this->assertStringContainsString('?page_valid=4"', $pager->links('valid'));
103+
$this->assertStringContainsString('?page_user=1"', $pager->links('user'));
104+
$this->assertStringContainsString('?page_user=2"', $pager->links('user'));
105+
$this->assertStringContainsString('?page_user=3"', $pager->links('user'));
106+
$this->assertStringContainsString('?page_user=4"', $pager->links('user'));
107+
}
82108
}

0 commit comments

Comments
 (0)