diff --git a/resources/views/tags/tag.blade.php b/resources/views/tags/tag.blade.php index 792dcab..9eb2b86 100644 --- a/resources/views/tags/tag.blade.php +++ b/resources/views/tags/tag.blade.php @@ -1 +1 @@ -<{{ $tag }} $value) : ?> {{ $name }}="{{ $value }}">{!! $inner !!} \ No newline at end of file +<{{ $tag }} $value) : ?> {{ $name }}="{{ $value }}">{{ $inner }} \ No newline at end of file diff --git a/src/Schema/ArticleSchema.php b/src/Schema/ArticleSchema.php index a7e79be..f70587c 100644 --- a/src/Schema/ArticleSchema.php +++ b/src/Schema/ArticleSchema.php @@ -4,6 +4,7 @@ use Carbon\CarbonInterface; use Illuminate\Support\Collection; +use Illuminate\Support\HtmlString; use RalphJSmit\Laravel\SEO\Support\SEOData; class ArticleSchema extends Schema @@ -75,9 +76,9 @@ public function initializeMarkup(SEOData $SEOData, array $markupBuilders): void } } - public function generateInner(): string + public function generateInner(): HtmlString { - return collect([ + $inner = collect([ '@context' => 'https://schema.org', '@type' => $this->type, 'mainEntityOfPage' => [ @@ -94,5 +95,7 @@ public function generateInner(): string ->when($this->articleBody, fn (Collection $collection): Collection => $collection->put('articleBody', $this->articleBody)) ->pipeThrough($this->markupTransformers) ->toJson(); + + return new HtmlString($inner); } } diff --git a/src/Schema/BreadcrumbListSchema.php b/src/Schema/BreadcrumbListSchema.php index 4cbb442..7e48ed1 100644 --- a/src/Schema/BreadcrumbListSchema.php +++ b/src/Schema/BreadcrumbListSchema.php @@ -3,6 +3,7 @@ namespace RalphJSmit\Laravel\SEO\Schema; use Illuminate\Support\Collection; +use Illuminate\Support\HtmlString; use RalphJSmit\Laravel\SEO\Support\SEOData; class BreadcrumbListSchema extends Schema @@ -27,9 +28,9 @@ public function initializeMarkup(SEOData $SEOData, array $markupBuilders): void ]); } - public function generateInner(): string + public function generateInner(): HtmlString { - return collect([ + $inner = collect([ '@context' => 'https://schema.org', '@type' => $this->type, 'itemListElement' => $this->breadcrumbs @@ -44,6 +45,8 @@ public function generateInner(): string ]) ->pipeThrough($this->markupTransformers) ->toJson(); + + return new HtmlString($inner); } public function prependBreadcrumbs(array $breadcrumbs): static diff --git a/src/Schema/Schema.php b/src/Schema/Schema.php index 2d4294b..265a9d3 100644 --- a/src/Schema/Schema.php +++ b/src/Schema/Schema.php @@ -4,6 +4,7 @@ use Closure; use Illuminate\Support\Collection; +use Illuminate\Support\HtmlString; use RalphJSmit\Helpers\Laravel\Pipe\Pipeable; use RalphJSmit\Laravel\SEO\Support\SEOData; use RalphJSmit\Laravel\SEO\Support\Tag; @@ -24,6 +25,8 @@ abstract class Schema extends Tag public string $tag = 'script'; + public HtmlString $inner; + public function __construct(SEOData $SEOData, array $markupBuilders = []) { $this->initializeMarkup($SEOData, $markupBuilders); @@ -33,7 +36,7 @@ public function __construct(SEOData $SEOData, array $markupBuilders = []) $this->inner = $this->generateInner(); } - abstract public function generateInner(): string; + abstract public function generateInner(): HtmlString; abstract public function initializeMarkup(SEOData $SEOData, array $markupBuilders): void; diff --git a/tests/Feature/Tags/OpenGraphTagsTest.php b/tests/Feature/Tags/OpenGraphTagsTest.php index 06291d0..a0697e5 100644 --- a/tests/Feature/Tags/OpenGraphTagsTest.php +++ b/tests/Feature/Tags/OpenGraphTagsTest.php @@ -139,3 +139,17 @@ get(route('seo.test-page', ['page' => $page])) ->assertSee('', false); }); + +it('will escape the title', function () { + config()->set('seo.title.suffix', ' - A & B'); + + $page = Page::create(); + $page->seo->update([ + 'title' => 'My page title', + ]); + + $page->refresh(); + + get(route('seo.test-page', ['page' => $page])) + ->assertSee('', false); +}); diff --git a/tests/Feature/Tags/TitleTagTest.php b/tests/Feature/Tags/TitleTagTest.php index 265bcff..af59234 100644 --- a/tests/Feature/Tags/TitleTagTest.php +++ b/tests/Feature/Tags/TitleTagTest.php @@ -45,3 +45,11 @@ get(route('seo.test-page', ['page' => $page])) ->assertSee('1 | Laravel SEO', false); }); + +it('will escape the title', function () { + config()->set('seo.title.infer_title_from_url', true); + config()->set('seo.title.suffix', ' - A & B'); + + get(route('seo.test-plain')) + ->assertSee('Test Plain - A & B', false); +}); diff --git a/tests/Feature/Tags/TwitterCardSummaryTagsTest.php b/tests/Feature/Tags/TwitterCardSummaryTagsTest.php index d82072b..b9974bb 100644 --- a/tests/Feature/Tags/TwitterCardSummaryTagsTest.php +++ b/tests/Feature/Tags/TwitterCardSummaryTagsTest.php @@ -109,3 +109,17 @@ get(route('seo.test-page', ['page' => $page])) ->assertSee('', false); }); + +it('will escape the title', function () { + config()->set('seo.title.suffix', ' - A & B'); + + $page = Page::create(); + $page->seo->update([ + 'title' => 'My page title', + ]); + + $page->refresh(); + + get(route('seo.test-page', ['page' => $page])) + ->assertSee('', false); +});