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

Fall Back to Entry id if Entry Links Do Not Exist #11

Merged
merged 1 commit into from Nov 21, 2023

Conversation

sabine
Copy link
Contributor

@sabine sabine commented Nov 21, 2023

It is legal for an Atom feed to not have links.

In this case, it appears sensible to rely on the value provided by the id tag.

@tmattio tmattio self-requested a review November 21, 2023 15:05
@tmattio tmattio self-assigned this Nov 21, 2023
lib/post.ml Outdated
@@ -163,7 +163,7 @@ let post_of_atom ~(feed : Feed.t) (e : Syndic.Atom.entry) =
(List.find (fun l -> l.Syndic.Atom.rel = Syndic.Atom.Alternate) e.links)
.href
with Not_found -> (
match e.links with l :: _ -> Some l.href | [] -> None)
match e.links with l :: _ -> Some l.href | [] -> Some e.id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we check that id is a valid URL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://www.ietf.org/rfc/rfc4287.txt

It seems that, even if the URI is valid, there's no guarantee that a resource can be fetched via HTTP (i.e. it's allowed for Atom feeds to declare resources that are not dereferencable).

4.2.6.  The "atom:id" Element

   The "atom:id" element conveys a permanent, universally unique
   identifier for an entry or feed.

   atomId = element atom:id {
      atomCommonAttributes,
      (atomUri)
   }

   Its content MUST be an IRI, as defined by [RFC3987].  Note that the
   definition of "IRI" excludes relative references.  Though the IRI
   might use a dereferencable scheme, Atom Processors MUST NOT assume it
   can be dereferenced.

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 added a check on the URI scheme, so that we only recognise this as a link if the scheme is "http" or "https".

@sabine
Copy link
Contributor Author

sabine commented Nov 21, 2023

With these changes, the feed from ocaml/ocaml.org#1776 is consumed successfully.

@sabine sabine marked this pull request as ready for review November 21, 2023 16:13
@tmattio tmattio merged commit 9c96111 into tarides:master Nov 21, 2023
@tmattio
Copy link
Collaborator

tmattio commented Nov 21, 2023

Thank you!

@sabine sabine deleted the fallback_to_id_if_no_links branch November 21, 2023 16:19
tmattio added a commit to tmattio/opam-repository that referenced this pull request Nov 21, 2023
CHANGES:

- Fall back to entry id if entry links doesn't exist (tarides/river#11, @sabine)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants