]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/bookmark/LinkUtils.php
Fix an issue truncating extracted metadata content
[github/shaarli/Shaarli.git] / application / bookmark / LinkUtils.php
index 17c379796cd39b239be09459d78e3cad22fdfb0b..a74fda5795c09e9f0fd6b3ed1e8d98b81226bc5d 100644 (file)
@@ -68,16 +68,16 @@ function html_extract_tag($tag, $html)
     $properties = implode('|', $propertiesKey);
     // We need a OR here to accept either 'property=og:noquote' or 'property="og:unrelated og:my-tag"'
     $orCondition  = '["\']?(?:og:)?'. $tag .'["\']?|["\'][^\'"]*?(?:og:)?' . $tag . '[^\'"]*?[\'"]';
-    // Try to retrieve OpenGraph image.
-    $ogRegex = '#<meta[^>]+(?:'. $properties .')=(?:'. $orCondition .')[^>]*content=["\'](.*?)["\'].*?>#';
+    // Try to retrieve OpenGraph tag.
+    $ogRegex = '#<meta[^>]+(?:'. $properties .')=(?:'. $orCondition .')[^>]*content=(["\'])([^\1]*?)\1.*?>#';
     // If the attributes are not in the order property => content (e.g. Github)
     // New regex to keep this readable... more or less.
-    $ogRegexReverse = '#<meta[^>]+content=["\'](.*?)["\'][^>]+(?:'. $properties .')=(?:'. $orCondition .').*?>#';
+    $ogRegexReverse = '#<meta[^>]+content=(["\'])([^\1]*?)\1[^>]+(?:'. $properties .')=(?:'. $orCondition .').*?>#';
 
     if (preg_match($ogRegex, $html, $matches) > 0
         || preg_match($ogRegexReverse, $html, $matches) > 0
     ) {
-        return $matches[1];
+        return $matches[2];
     }
 
     return false;