Skip to content

Commit

Permalink
Fixed checking for too long path length (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna authored Apr 20, 2021
1 parent b2a4844 commit ab22581
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
33 changes: 33 additions & 0 deletions src/Icon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Orchid\Icons;

use Illuminate\Contracts\Support\Htmlable;

class Icon implements Htmlable
{
/**
* @var string|null
*/
protected $content;

/**
* Icon constructor.
*
* @param string|null $content
*/
public function __construct(string $content = null)
{
$this->content = $content;
}

/**
* @return string|null
*/
public function toHtml(): ?string
{
return $this->content;
}
}
6 changes: 4 additions & 2 deletions src/IconComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ public function __construct(
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\View\View|string
* @return Icon
*/
public function render()
{
$icon = $this->finder->loadFile($this->path);

return $this->setAttributes($icon);
$content = $this->setAttributes($icon);

return new Icon($content);
}

/**
Expand Down
14 changes: 14 additions & 0 deletions tests/BladeComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,18 @@ public function testAttibutesComponent(): void
$this->assertStringContainsString('width="2em"', $view);
$this->assertStringContainsString('height="2em"', $view);
}


/**
* https://github.com/laravel/framework/issues/32254
*/
public function testLongContentComponent(): void
{
$this->app->make(IconFinder::class)
->registerIconDirectory('empty', __DIR__ . '/stubs');

$view = view('icon-long-view-content')->render();

$this->assertEmpty($view);
}
}
1 change: 1 addition & 0 deletions tests/views/icon-long-view-content.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<x-orchid-icon path="{{ str_repeat('a', 9999999) }}" class="icon-big" width="2em" height="2em" />

0 comments on commit ab22581

Please sign in to comment.