Skip to content

Commit 5752509

Browse files
committed
Address copilot reviews
1 parent 4e213da commit 5752509

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

resources/js/app.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,14 @@ Alpine.data('packageSearch', () => ({
112112
},
113113

114114
selectResult(result) {
115-
window.open(result.repo_url, '_blank', 'noopener,noreferrer')
115+
try {
116+
const url = new URL(result.repo_url)
117+
if (url.protocol === 'https:') {
118+
window.open(url.toString(), '_blank', 'noopener,noreferrer')
119+
}
120+
} catch {
121+
// Invalid URL, ignore
122+
}
116123
this.close()
117124
},
118125

src/Controller/PackagesController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function autocomplete(): Response
110110
if (mb_strlen($q) < 2) {
111111
return $this->response
112112
->withType('application/json')
113-
->withStringBody(json_encode([]));
113+
->withStringBody(json_encode([], JSON_THROW_ON_ERROR));
114114
}
115115

116116
$packages = $this->Packages
@@ -143,7 +143,7 @@ public function autocomplete(): Response
143143

144144
return $this->response
145145
->withType('application/json')
146-
->withStringBody(json_encode($results));
146+
->withStringBody(json_encode($results, JSON_THROW_ON_ERROR));
147147
}
148148

149149
/**

src/Model/Table/PackagesTable.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ public function validationDefault(Validator $validator): Validator
105105
*/
106106
public function findAutocomplete(SelectQuery $query, string $search, int $maxResults = 8): SelectQuery
107107
{
108+
$escapedSearch = str_replace(['%', '_'], ['\%', '\_'], $search);
109+
108110
return $query
109111
->find('search', search: ['search' => $search])
110112
->contain(['Tags' => function (SelectQuery $q) {
@@ -113,7 +115,7 @@ public function findAutocomplete(SelectQuery $query, string $search, int $maxRes
113115
->selectAlso([
114116
'name_match' => $query->expr()
115117
->case()
116-
->when(['Packages.package LIKE' => '%' . $search . '%'])
118+
->when(['Packages.package LIKE' => '%' . $escapedSearch . '%'])
117119
->then(1, 'integer')
118120
->else(0, 'integer'),
119121
])

templates/element/navbar.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
</div>
5151
</div>
5252
</li>
53-
<div class="divider my-0"></div>
53+
<li role="separator" class="p-0"><hr class="divider my-0" /></li>
5454
<li>
5555
<?= $this->Html->link('Sign out', [
5656
'controller' => 'Users',
@@ -92,7 +92,7 @@
9292
<li><?= $this->Html->link('Docs', 'https://book.cakephp.org/', ['target' => '_blank', 'rel' => 'noopener']) ?></li>
9393
<li><?= $this->Html->link('API', 'https://api.cakephp.org/', ['target' => '_blank', 'rel' => 'noopener']) ?></li>
9494
<?php if (!$this->Identity->isLoggedIn()) : ?>
95-
<div class="divider my-0"></div>
95+
<li role="separator" class="p-0"><hr class="divider my-0" /></li>
9696
<li>
9797
<?= $this->Form->postLink(
9898
'Sign in with GitHub',

templates/element/search.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
class="grow min-w-0"
4949
autocomplete="off"
5050
role="combobox"
51-
aria-expanded="false"
5251
:aria-expanded="open"
5352
aria-haspopup="listbox"
5453
aria-controls="autocomplete-listbox"

tests/TestCase/View/Helper/UserHelperTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
class UserHelperTest extends TestCase
1414
{
15-
protected UserHelper $User;
16-
1715
protected function createHelper(?array $identityData = null): UserHelper
1816
{
1917
$request = new ServerRequest();

0 commit comments

Comments
 (0)