Skip to content

Commit 6f31082

Browse files
committed
fix: [bookmarks] added more error handling for malformed bookmarks
1 parent 4f42d50 commit 6f31082

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/Model/Table/UserSettingsTable.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,13 @@ public function deleteBookmark($user, $data)
144144
*/
145145
public function validURI(String $uri): bool
146146
{
147-
$parsed = parse_url($uri);
148-
$isLocalPath = empty($parsed['scheme']) && empty($parsed['domain']) && !empty($parsed['path']);
149-
$isValidURL = !empty($parsed['scheme']) && in_array($parsed['scheme'], ['http', 'https']) && filter_var($uri, FILTER_SANITIZE_URL);
147+
try {
148+
$parsed = parse_url($uri);
149+
$isLocalPath = empty($parsed['scheme']) && empty($parsed['domain']) && !empty($parsed['path']);
150+
$isValidURL = !empty($parsed['scheme']) && in_array($parsed['scheme'], ['http', 'https']) && filter_var($uri, FILTER_SANITIZE_URL);
151+
} catch (\Exception $e) {
152+
return false;
153+
}
150154
return $isLocalPath || $isValidURL;
151155
}
152156
}

templates/Instance/home.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
<ul class="col-sm-12 col-md-10 col-l-8 col-xl-8 mb-3">
1919
<?php foreach ($bookmarks as $bookmark) : ?>
2020
<li class="list-group-item">
21-
<?php if ($this->userSettingsTable->validURI($bookmark['url'])): ?>
21+
<?php if (!empty($bookmark['url']) && $this->userSettingsTable->validURI($bookmark['url'])): ?>
2222
<a href="<?= h($bookmark['url']) ?>" class="w-bold">
2323
<?= h($bookmark['label']) ?>
2424
</a>
2525
<?php else: ?>
2626
<span class="w-bold">
27-
<?= h($bookmark['url']) ?>
27+
<?= !empty($bookmark['url']) ? h($bookmark['url']) : '' ?>
2828
</span>
2929
<?php endif; ?>
30-
<span class="ms-3 fw-light"><?= h($bookmark['name']) ?></span>
30+
<span class="ms-3 fw-light"><?= !empty($bookmark['name']) ? h($bookmark['name']): '' ?></span>
3131
</li>
3232
<?php endforeach; ?>
3333
</ul>

0 commit comments

Comments
 (0)