Improve removal of h-card if it doesn't match page URL

Open
#122 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
54/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
php

Research direction

Start with the filtering logic in lib/XRay/Formats/Mf2.php at the linked lines and compare its behavior with the supplied example. Add a regression test for an h-card with no url property, then verify that such a card is removed while non-h-cards and h-cards whose url matches the page URL remain.

Written by the indexing model from the issue text.

Description

This bit of code is intended to remove h-cards from implicit feeds of h-* when parsing:

https://github.com/aaronpk/XRay/blob/a4cda273d34c56317197511d0f4799f5f00465e9/lib/XRay/Formats/Mf2.php#L36

It appears the logic doesn't work quite right if the h-card has no url property. In this example, the parsed mf2 is (snipped out parts not needed for this example):

"items": [
    {
        "type": [
            "h-entry"
        ],
        "properties": {
            "url": [],
            "published": [],
            "author": [],
            "like-of": []
        },
        "lang": "en"
    },
    {
        "type": [
            "h-card"
        ],
        "properties": {
            "name": [
                "RSS \u00b7 Webmentions"
            ]
        },
        "lang": "en"
    }
],

This is a bit more verbose in part to make it easier to follow, but I think the array_filter should be something like:

$tmpmf2 = array_filter($items, function($item) use($url) {
  if (!in_array('h-card', $item['type'])) {
    // not an h-card; keep it in the result array
    return true;
  }

  if (
    isset($item['properties']['url'][0])
    && $item['properties']['url'][0] == $url
  ) {
    // h-card's u-url matches page URL; keep it in the result array
    return true;
  }

  // h-card u-url does *not* match page URL (or it has no u-url); remove it from result array
  return false;
});

I haven't written a unit test for this yet, otherwise I would make it a PR. It did work in my local testing with the specific example link above.

I might be able to make a PR in the near future, or if someone else wants to take it on, feel free!

Dominant language
PHP
Stars
96
Forks
17
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from aaronpk/XRay

All issues in aaronpk/XRay

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.