Fix Issue #82: ampersand in url in sites.json breaks icon

This commit is contained in:
Dale Davies
2023-04-04 14:15:27 +01:00
parent 8aad20147b
commit 260e886db8
3 changed files with 7 additions and 6 deletions

View File

@@ -18,14 +18,15 @@ use \Jump\Exceptions\APIException;
class Icon extends AbstractAPI {
public function get_output(): string {
if (!isset($this->routeparams['siteurl']) || empty($this->routeparams['siteurl'])) {
throw new APIException('The siteurl query parameter is not provided or empty');
if (!isset($this->routeparams['siteid']) || empty($this->routeparams['siteid'])) {
throw new APIException('The siteid query parameter is not provided or empty');
}
$sites = new \Jump\Sites($this->config, $this->cache);
$siteurl = filter_var($this->routeparams['siteurl'], FILTER_SANITIZE_URL);
$site = $sites->get_site_by_url($siteurl);
# A site ID can contain lowercase a-z, 0-9 and the "-" (dash) character only.
$siteid = preg_replace("/[^a-z0-9-]/", "", $this->routeparams['siteid']);
$site = $sites->get_site_by_id($siteid);
$imagedata = $site->get_favicon_image_data();

View File

@@ -34,7 +34,7 @@ class Main {
$this->router->addRoute('/tag/<tag>', [
'class' => 'Jump\Pages\TagPage'
]);
$this->router->addRoute('/api/icon?siteurl=<siteurl>', [
$this->router->addRoute('/api/icon?siteid=<siteid>', [
'class' => 'Jump\API\Icon'
]);
$this->router->addRoute('/api/status[/<token>]', [

View File

@@ -2,7 +2,7 @@
<ul class="sites {{# altlayout}}alternate{{/ altlayout}}">
{{# sites}}<li id="{{id}}"><a {{# newtab}}target="_blank"{{/ newtab}} rel="{{# nofollow}}nofollow {{/ nofollow}}{{# newtab}}noopener{{/ newtab}}" title="{{description}}" href="{{url}}">
<span class="icon">
<img src="{{{wwwurl}}}/api/icon?siteurl={{#urlencode}}{{url}}{{/urlencode}}">
<img src="{{{wwwurl}}}/api/icon?siteid={{id}}">
</span>
<span class="name">{{name}}</span>
</a></li>{{/ sites}}