Skip to content

Commit 5c20ec3

Browse files
committed
bug #2314 [Icons] Fix commands receive polluted SVG (smnandre)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Icons] Fix commands receive polluted SVG | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Issues | Fix #2223 | License | MIT These commands were getting SVG with CSS size attributes Fix #2223 Commits ------- cc238cb [Icons] Fix commands receive polluted SVG
2 parents 75054e7 + cc238cb commit 5c20ec3

File tree

4 files changed

+4
-55
lines changed

4 files changed

+4
-55
lines changed

src/Icons/src/Command/ImportIconCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6868
$io->comment(\sprintf('Importing %s...', $fullName));
6969

7070
try {
71-
$svg = $this->iconify->fetchSvg($prefix, $name);
71+
$iconSvg = $this->iconify->fetchIcon($prefix, $name)->toHtml();
7272
} catch (IconNotFoundException $e) {
7373
$io->error($e->getMessage());
7474
$result = Command::FAILURE;
@@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7979
$cursor = new Cursor($output);
8080
$cursor->moveUp(2);
8181

82-
$this->registry->add(\sprintf('%s/%s', $prefix, $name), $svg);
82+
$this->registry->add(\sprintf('%s/%s', $prefix, $name), $iconSvg);
8383

8484
$license = $this->iconify->metadataFor($prefix)['license'];
8585

src/Icons/src/Command/LockIconsCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8181
}
8282

8383
try {
84-
$svg = $this->iconify->fetchSvg($prefix, $name);
84+
$iconSvg = $this->iconify->fetchIcon($prefix, $name)->toHtml();
8585
} catch (IconNotFoundException) {
8686
// icon not found on iconify
8787
if ($io->isVerbose()) {
@@ -90,7 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9090
continue;
9191
}
9292

93-
$this->registry->add(\sprintf('%s/%s', $prefix, $name), $svg);
93+
$this->registry->add(\sprintf('%s/%s', $prefix, $name), $iconSvg);
9494

9595
$license = $this->iconify->metadataFor($prefix)['license'];
9696
++$count;

src/Icons/src/Iconify.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,25 +85,6 @@ public function fetchIcon(string $prefix, string $name): Icon
8585
]);
8686
}
8787

88-
public function fetchSvg(string $prefix, string $name): string
89-
{
90-
if (!isset($this->sets()[$prefix])) {
91-
throw new IconNotFoundException(\sprintf('The icon "%s:%s" does not exist on iconify.design.', $prefix, $name));
92-
}
93-
94-
$response = $this->http->request('GET', \sprintf('/%s/%s.svg', $prefix, $name));
95-
96-
if (200 !== $response->getStatusCode()) {
97-
throw new IconNotFoundException(\sprintf('The icon "%s:%s" does not exist on iconify.design.', $prefix, $name));
98-
}
99-
100-
if (!str_starts_with($svg = $response->getContent(), '<svg')) {
101-
throw new IconNotFoundException(\sprintf('The icon "%s:%s" does not exist on iconify.design.', $prefix, $name));
102-
}
103-
104-
return $svg;
105-
}
106-
10788
public function hasIconSet(string $prefix): bool
10889
{
10990
return isset($this->sets()[$prefix]);

src/Icons/tests/Unit/IconifyTest.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\Cache\Adapter\NullAdapter;
1616
use Symfony\Component\HttpClient\MockHttpClient;
1717
use Symfony\Component\HttpClient\Response\JsonMockResponse;
18-
use Symfony\Component\HttpClient\Response\MockResponse;
1918
use Symfony\UX\Icons\Exception\IconNotFoundException;
2019
use Symfony\UX\Icons\Iconify;
2120

@@ -173,37 +172,6 @@ public function testGetMetadata(): void
173172
$this->assertSame('Font Awesome Solid', $metadata['name']);
174173
}
175174

176-
public function testFetchSvg(): void
177-
{
178-
$client = new MockHttpClient([
179-
new MockResponse(file_get_contents(__DIR__.'/../Fixtures/Iconify/collections.json'), [
180-
'response_headers' => ['content-type' => 'application/json'],
181-
]),
182-
new MockResponse(file_get_contents(__DIR__.'/../Fixtures/Iconify/icon.svg')),
183-
]);
184-
$iconify = new Iconify(new NullAdapter(), 'https://localhost', $client);
185-
186-
$svg = $iconify->fetchSvg('fa6-regular', 'bar');
187-
188-
$this->assertIsString($svg);
189-
$this->stringContains('-.224l.235-.468ZM6.013 2.06c-.649-.1', $svg);
190-
}
191-
192-
public function testFetchSvgThrowIconNotFoundExceptionWhenStatusCodeNot200(): void
193-
{
194-
$client = new MockHttpClient([
195-
new MockResponse(file_get_contents(__DIR__.'/../Fixtures/Iconify/collections.json'), [
196-
'response_headers' => ['content-type' => 'application/json'],
197-
]),
198-
new MockResponse('', ['http_code' => 404]),
199-
]);
200-
$iconify = new Iconify(new NullAdapter(), 'https://localhost', $client);
201-
202-
$this->expectException(IconNotFoundException::class);
203-
204-
$iconify->fetchSvg('fa6-regular', 'bar');
205-
}
206-
207175
private function createHttpClient(mixed $data, int $code = 200): MockHttpClient
208176
{
209177
$mockResponse = new JsonMockResponse($data, ['http_code' => $code]);

0 commit comments

Comments
 (0)