]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Fixes #512: retrieving title didn't match the first closing tag 513/head
authorArthurHoaro <arthur@hoa.ro>
Tue, 8 Mar 2016 09:00:53 +0000 (10:00 +0100)
committerArthurHoaro <arthur@hoa.ro>
Tue, 8 Mar 2016 09:00:53 +0000 (10:00 +0100)
application/LinkUtils.php
tests/LinkUtilsTest.php

index 26dd6b6794c402464c007b647a5cd5dbe9a9b19f..d8dc8b5e01a2dc01112cdb5b874626012c650d10 100644 (file)
@@ -9,7 +9,7 @@
  */
 function html_extract_title($html)
 {
-    if (preg_match('!<title>(.*)</title>!is', $html, $matches)) {
+    if (preg_match('!<title>(.*?)</title>!is', $html, $matches)) {
         return trim(str_replace("\n", ' ', $matches[1]));
     }
     return false;
index c22575907c144e37dccfa6489731f1260d82347c..609a80cbe6b223f25b7060389f55e7ae807d26f3 100644 (file)
@@ -15,6 +15,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
         $title = 'Read me please.';
         $html = '<html><meta>stuff</meta><title>'. $title .'</title></html>';
         $this->assertEquals($title, html_extract_title($html));
+        $html = '<html><title>'. $title .'</title>blabla<title>another</title></html>';
+        $this->assertEquals($title, html_extract_title($html));
     }
 
     /**