diff options
| author | 2022-03-22 23:12:22 +0100 | |
|---|---|---|
| committer | 2022-03-22 23:12:22 +0100 | |
| commit | b0a63355b66d0cc431c9b1af96622c2360207565 (patch) | |
| tree | 24bf04d71f7ecba33f807a0e4d4b8f5ae7c92dcf | |
| parent | 7d00ad8ed75cae5dafd4ac1f2cc6e15e94333628 (diff) | |
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"
```
| -rw-r--r-- | app/Models/Feed.php | 10 | ||||
| -rw-r--r-- | lib/SimplePie/SimplePie.php | 12 |
2 files changed, 15 insertions, 7 deletions
diff --git a/app/Models/Feed.php b/app/Models/Feed.php index baaf448f8..f43237b00 100644 --- a/app/Models/Feed.php +++ b/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é diff --git a/lib/SimplePie/SimplePie.php b/lib/SimplePie/SimplePie.php index bf4a66bb4..60edf5274 100644 --- a/lib/SimplePie/SimplePie.php +++ b/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']; } } |
