Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of HTTP Links #729

Merged
merged 1 commit into from May 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions library/SimplePie.php
Expand Up @@ -2666,12 +2666,14 @@ public function get_links($rel = 'alternate')
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) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can $this->data['headers']['link'] be anything other than array or string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not believe so. And this PR does not change the assumptions (there was already a case for array and string before).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, is not is_string($link_headers) redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, but it is not something that is currently enforced (e.g. through a type), and I have not checked in details

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'];
}
}

Expand Down