Skip to content

Commit 42704c2

Browse files
committed
Fix properties with double quotes in it
1 parent 616071a commit 42704c2

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/Property.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public static function make(string $prefix, string $property, string $content)
2727

2828
public function __toString(): string
2929
{
30-
return "<meta property=\"{$this->prefix}:{$this->property}\" content=\"{$this->content}\">";
30+
$content = str_replace('"', '&quot;', $this->content);
31+
32+
return "<meta property=\"{$this->prefix}:{$this->property}\" content=\"{$content}\">";
3133
}
3234
}

tests/GlobalTypesTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@
2020
assertMatchesHtmlSnapshot((string) $og);
2121
})->group('global', 'website');
2222

23+
it('can generate website tags with quotes', function () {
24+
$og = Website::make('Title "\'&&amp; | Example')
25+
->url('http://www.example.com')
26+
->description('Description')
27+
->locale('en_US')
28+
->alternateLocale('en_GB')
29+
->siteName('Example')
30+
->image('http://www.example.com/image1.jpg');
31+
32+
assertMatchesHtmlSnapshot((string) $og);
33+
})->group('global', 'website');
34+
2335
it('can generate website tags with stringable image', function () {
2436
$og = Website::make('Title | Example')
2537
->url('http://www.example.com')
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
2+
<html><head>
3+
<meta property="og:type" content="website">
4+
<meta property="og:title" content="Title &quot;'&amp;&amp; | Example">
5+
<meta property="og:url" content="http://www.example.com">
6+
<meta property="og:description" content="Description">
7+
<meta property="og:locale" content="en_US">
8+
<meta property="og:locale:alternate" content="en_GB">
9+
<meta property="og:site_name" content="Example">
10+
<meta property="og:image" content="http://www.example.com/image1.jpg">
11+
</head></html>

0 commit comments

Comments
 (0)