Skip to content
This repository was archived by the owner on Mar 12, 2020. It is now read-only.

Commit 16badb1

Browse files
authored
Merge pull request #18 from phergie/hotfix/url-title
Make Mime\Html->extract() title parsing a bit better
2 parents 78b4570 + f65fc5a commit 16badb1

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Mime/Html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function matches($mimeType)
4141
*/
4242
public function extract(array $replacements, UrlInterface $url)
4343
{
44-
if (preg_match('#<title[^>]*>(.*?)</title>#is', $url->getBody(), $match)) {
44+
if (preg_match('#<title[^>]*>([^<]+)</title>#is', $url->getBody(), $match)) {
4545
$replacements['%composed-title%'] =
4646
$replacements['%title%'] =
4747
preg_replace('/[\s\v]+/', ' ', trim(html_entity_decode($match[1], ENT_QUOTES | ENT_HTML5)));

tests/Mime/HtmlTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ public function testExtractProvider() {
6060
),
6161
new Url('', '<html><title>foo&#39;s w&ouml;rk</title></html></html>', array(), 200, 1),
6262
),
63+
array(
64+
array(
65+
'%title%' => 'Avatar: The Last Airbender Is Returning as a New Netflix Series',
66+
'%composed-title%' => 'Avatar: The Last Airbender Is Returning as a New Netflix Series',
67+
),
68+
new Url('', '<title>pq-earther<\/title><path /><title>Avatar: The Last Airbender Is Returning as a New Netflix Series</title>', array(), 200, 1),
69+
),
6370
array(
6471
array(),
6572
new Url('', '', array(), 200, 1),

0 commit comments

Comments
 (0)