Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
smnandre committed Nov 8, 2024
1 parent 182c17a commit 2acdba8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Icons/src/Iconify.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,16 @@ public function fetchIcons(string $prefix, array $names): array
}

// Sort to enforce cache hits
\sort($names);
$queryString = implode(',', $names);
if (!preg_match('#^[\w-]+(,[\w-]+)*$#', $queryString)) {
if (!preg_match('#^[a-z0-9-,]+$#', $queryString)) {
throw new \InvalidArgumentException('Invalid icon names.');
}

// 500 chars max
// 42 chars: https://api.iconify.design/mdi.json?icons=
if (450 < \strlen($queryString)) {
// URL must be 500 chars max (iconify limit)
// -39 chars: https://api.iconify.design/XXX.json?icons=
// -safe margin
if (450 < \strlen($prefix.$queryString)) {
throw new \InvalidArgumentException('The query string is too long.');
}

Expand All @@ -108,7 +110,7 @@ public function fetchIcons(string $prefix, array $names): array
'Accept' => 'application/json',
],
'query' => [
'icons' => $queryString,
'icons' => strtolower($queryString),
],
]);

Expand All @@ -124,7 +126,7 @@ public function fetchIcons(string $prefix, array $names): array
$width = $iconData['width'] ?? $data['width'] ??= $this->sets()[$prefix]['width'] ?? null;

$icons[$iconName] = new Icon($iconData['body'], [
'viewBox' => \sprintf('0 0 %s %s', $width ?? $height, $height ?? $width),
'viewBox' => \sprintf('0 0 %d %d', $width ?? $height, $height ?? $width),
]);
}

Expand Down

0 comments on commit 2acdba8

Please sign in to comment.