diff --git a/src/Support/OpenGraphTag.php b/src/Support/OpenGraphTag.php
index 1cd2a2e..f975866 100644
--- a/src/Support/OpenGraphTag.php
+++ b/src/Support/OpenGraphTag.php
@@ -3,6 +3,7 @@
namespace RalphJSmit\Laravel\SEO\Support;
use Illuminate\Support\Collection;
+use Illuminate\Support\HtmlString;
class OpenGraphTag extends Tag
{
@@ -10,13 +11,13 @@ class OpenGraphTag extends Tag
public function __construct(
string $property,
- string $content,
+ string | HtmlString $content,
) {
$this->attributes['property'] = $property;
$this->attributes['content'] = $content;
$this->attributesPipeline[] = function (Collection $collection) {
- return $collection->mapWithKeys(function ($value, $key) {
+ return $collection->mapWithKeys(function (mixed $value, string $key) {
if ($key === 'property') {
$value = 'og:' . $value;
}
diff --git a/src/Support/TwitterCardTag.php b/src/Support/TwitterCardTag.php
index a8e8da6..1c73c22 100644
--- a/src/Support/TwitterCardTag.php
+++ b/src/Support/TwitterCardTag.php
@@ -3,6 +3,7 @@
namespace RalphJSmit\Laravel\SEO\Support;
use Illuminate\Support\Collection;
+use Illuminate\Support\HtmlString;
class TwitterCardTag extends Tag
{
@@ -10,13 +11,13 @@ class TwitterCardTag extends Tag
public function __construct(
string $name,
- string $content,
+ string | HtmlString $content,
) {
$this->attributes['name'] = $name;
$this->attributes['content'] = $content;
$this->attributesPipeline[] = function (Collection $collection) {
- return $collection->mapWithKeys(function ($value, $key) {
+ return $collection->mapWithKeys(function (mixed $value, string $key) {
if ($key === 'name') {
$value = 'twitter:' . $value;
}
diff --git a/src/Tags/OpenGraphTags.php b/src/Tags/OpenGraphTags.php
index a172d72..1c2e4e9 100644
--- a/src/Tags/OpenGraphTags.php
+++ b/src/Tags/OpenGraphTags.php
@@ -4,6 +4,7 @@
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Support\Collection;
+use Illuminate\Support\HtmlString;
use RalphJSmit\Laravel\SEO\Support\MetaContentTag;
use RalphJSmit\Laravel\SEO\Support\OpenGraphTag;
use RalphJSmit\Laravel\SEO\Support\RenderableCollection;
@@ -32,7 +33,7 @@ public static function initialize(SEOData $SEOData): static
}
if ($SEOData->image) {
- $collection->push(new OpenGraphTag('image', $SEOData->image));
+ $collection->push(new OpenGraphTag('image', new HtmlString($SEOData->image)));
if ($SEOData->imageMeta) {
$collection
diff --git a/src/Tags/TwitterCard/Summary.php b/src/Tags/TwitterCard/Summary.php
index f8dd680..e5440f1 100644
--- a/src/Tags/TwitterCard/Summary.php
+++ b/src/Tags/TwitterCard/Summary.php
@@ -4,6 +4,7 @@
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Support\Collection;
+use Illuminate\Support\HtmlString;
use RalphJSmit\Laravel\SEO\Support\RenderableCollection;
use RalphJSmit\Laravel\SEO\Support\SEOData;
use RalphJSmit\Laravel\SEO\Support\TwitterCardTag;
@@ -37,7 +38,7 @@ public static function initialize(SEOData $SEOData): static
$collection->push(new TwitterCardTag('card', 'summary'));
if ($SEOData->image) {
- $collection->push(new TwitterCardTag('image', $SEOData->image));
+ $collection->push(new TwitterCardTag('image', new HtmlString($SEOData->image)));
if ($SEOData->imageMeta) {
$collection
diff --git a/src/Tags/TwitterCard/SummaryLargeImage.php b/src/Tags/TwitterCard/SummaryLargeImage.php
index fba8032..1e64aba 100644
--- a/src/Tags/TwitterCard/SummaryLargeImage.php
+++ b/src/Tags/TwitterCard/SummaryLargeImage.php
@@ -4,6 +4,7 @@
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Support\Collection;
+use Illuminate\Support\HtmlString;
use RalphJSmit\Laravel\SEO\Support\RenderableCollection;
use RalphJSmit\Laravel\SEO\Support\SEOData;
use RalphJSmit\Laravel\SEO\Support\TwitterCardTag;
@@ -37,7 +38,7 @@ public static function initialize(SEOData $SEOData): static
$collection->push(new TwitterCardTag('card', 'summary_large_image'));
if ($SEOData->image) {
- $collection->push(new TwitterCardTag('image', $SEOData->image));
+ $collection->push(new TwitterCardTag('image', new HtmlString($SEOData->image)));
if ($SEOData->imageMeta) {
$collection
diff --git a/tests/Feature/Tags/OpenGraphTagsTest.php b/tests/Feature/Tags/OpenGraphTagsTest.php
index a0697e5..48f815d 100644
--- a/tests/Feature/Tags/OpenGraphTagsTest.php
+++ b/tests/Feature/Tags/OpenGraphTagsTest.php
@@ -153,3 +153,21 @@
get(route('seo.test-page', ['page' => $page]))
->assertSee('', false);
});
+
+it('will not escape the image URL query parameters', function () {
+ config()->set('seo.title.suffix', ' | Laravel SEO');
+ config()->set('seo.description.fallback', 'Fallback description');
+
+ $page = Page::create();
+
+ $page::$overrides = [
+ 'title' => 'Test Page',
+ 'image' => $url = 'https://website.test/images/xSVtl6ZF7fNuZIoXkZbzI2EzoAD.jpg?h=800&fit=contain&q=80&fm=webp',
+ ];
+
+ get(route('seo.test-page', ['page' => $page]))
+ ->assertSee('', false)
+ ->assertDontSee('assertDontSee('assertDontSee('twitter:site'); // We should not display an empty '@' username.
+});
diff --git a/tests/Feature/Tags/TwitterCardSummaryTagsTest.php b/tests/Feature/Tags/TwitterCardSummaryTagsTest.php
index 1d35130..e075a66 100644
--- a/tests/Feature/Tags/TwitterCardSummaryTagsTest.php
+++ b/tests/Feature/Tags/TwitterCardSummaryTagsTest.php
@@ -79,6 +79,27 @@
['summary_large_image', 'images/twitter-3597x1799.jpg', '3597', '1799'],
]);
+it('will not escape the image URL query parameters', function () {
+ config()->set('seo.title.suffix', ' | Laravel SEO');
+ config()->set('seo.description.fallback', 'Fallback description');
+
+ $page = Page::create();
+
+ $page::$overrides = [
+ 'title' => 'Test Page',
+ 'image' => $url = 'https://website.test/images/xSVtl6ZF7fNuZIoXkZbzI2EzoAD.jpg?h=800&fit=contain&q=80&fm=webp',
+ ];
+
+ get(route('seo.test-page', ['page' => $page]))
+ ->assertSee('', false)
+ ->assertSee('', false)
+ ->assertSee('', false)
+ ->assertSee('', false)
+ ->assertDontSee('assertDontSee('assertDontSee('twitter:site'); // We should not display an empty '@' username.
+});
+
it('will not render the Twitter Card summary_large_image for too large or small images', function (string $imagePath) {
$page = Page::create();