Bladeren bron

SimplePie fix parsing of HTTP Links (#4283)

* SimplePie fix parsing of HTTP Links
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link
* https://datatracker.ietf.org/doc/html/rfc8288

Before, SimplePie was not able to parse something like

```
Link: <https://pubsubhubbub.appspot.com>; rel="hub", <https://pubsubhubbub.superfeedr.com>; rel=hub, <https://websubhub.com/hub>; rel="hub"
```
Alexandre Alapetite 4 jaren geleden
bovenliggende
commit
b0a63355b6
2 gewijzigde bestanden met toevoegingen van 15 en 7 verwijderingen
  1. 8 2
      app/Models/Feed.php
  2. 7 5
      lib/SimplePie/SimplePie.php

+ 8 - 2
app/Models/Feed.php

@@ -352,9 +352,15 @@ class FreshRSS_Feed extends Minz_Model {
 				}
 
 				$links = $simplePie->get_links('self');
-				$this->selfUrl = $links[0] ?? '';
+				$this->selfUrl = empty($links[0]) ? '' : checkUrl($links[0]);
+				if ($this->selfUrl == false) {
+					$this->selfUrl = '';
+				}
 				$links = $simplePie->get_links('hub');
-				$this->hubUrl = $links[0] ?? '';
+				$this->hubUrl = empty($links[0]) ? '' : checkUrl($links[0]);
+				if ($this->hubUrl == false) {
+					$this->hubUrl = '';
+				}
 
 				if ($loadDetails) {
 					// si on a utilisé l’auto-discover, notre url va avoir changé

+ 7 - 5
lib/SimplePie/SimplePie.php

@@ -2726,12 +2726,14 @@ class SimplePie
 		if (isset($this->data['headers']['link']))
 		{
 			$link_headers = $this->data['headers']['link'];
-			if (is_string($link_headers)) {
-				$link_headers = array($link_headers);
+			if (is_array($link_headers)) {
+				$link_headers = implode(',', $link_headers);
 			}
-			$matches = preg_filter('/<([^>]+)>; rel='.preg_quote($rel).'/', '$1', $link_headers);
-			if (!empty($matches)) {
-				return $matches;
+			// https://datatracker.ietf.org/doc/html/rfc8288
+			if (is_string($link_headers) &&
+				preg_match_all('/<(?P<uri>[^>]+)>\s*;\s*rel\s*=\s*(?P<quote>"?)' . preg_quote($rel) . '(?P=quote)\s*(?=,|$)/i', $link_headers, $matches))
+			{
+				return $matches['uri'];
 			}
 		}