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

Take into account a CollectionPage decoded as array #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

j3j5
Copy link

@j3j5 j3j5 commented Mar 4, 2023

When trying this library, I was trying to create a custom type for Mastodon following the docs. I've added my own type to support Note objects adding the missing properties but when I try to create a Note object with with of my own posts, I get the follwing TypeError:

 TypeError  property_exists(): Argument #1 ($object_or_class) must be of type object|string, array given.
--
0:  () at vendor/landrok/activitypub/src/ActivityPhp/Type/Util.php:201
1:  property_exists() at vendor/landrok/activitypub/src/ActivityPhp/Type/Util.php:201
2:  ActivityPhp\Type\Util::hasProperties() at vendor/landrok/activitypub/src/ActivityPhp/Type/Util.php:506

After some debugging I realized that when validating a CollectionPage, first it validates that is a valid Collection, which has a check in case the $item is not an array, so it'll convert it to object, and then, check that the $item has the typeOf property, but then is not doing the array-object conversion, hence the error.

This patch fixes that.

Here's the json file that produces the error. Fails when validating the first key. It's a json retrieved from Mastodon v4.0.2.

{
    "@context": [
        "https://www.w3.org/ns/activitystreams",
        {
            "ostatus": "http://ostatus.org#",
            "atomUri": "ostatus:atomUri",
            "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
            "conversation": "ostatus:conversation",
            "sensitive": "as:sensitive",
            "toot": "http://joinmastodon.org/ns#",
            "votersCount": "toot:votersCount",
            "Hashtag": "as:Hashtag"
        }
    ],
    "id": "https://hachyderm.io/users/j3j5/statuses/109321328485360034",
    "type": "Note",
    "summary": null,
    "inReplyTo": null,
    "published": "2022-11-10T20:11:31Z",
    "url": "https://hachyderm.io/@j3j5/109321328485360034",
    "attributedTo": "https://hachyderm.io/users/j3j5",
    "to": [
        "https://www.w3.org/ns/activitystreams#Public"
    ],
    "cc": [
        "https://hachyderm.io/users/j3j5/followers"
    ],
    "sensitive": false,
    "atomUri": "https://hachyderm.io/users/j3j5/statuses/109321328485360034",
    "inReplyToAtomUri": null,
    "conversation": "tag:hachyderm.io,2022-11-10:objectId=1050302:objectType=Conversation",
    "content": "\u003cp\u003eI\u0026#39;m buzzing with ideas on how to bring all my \u003ca href=\"https://hachyderm.io/tags/GoodBots\" class=\"mention hashtag\" rel=\"tag\"\u003e#\u003cspan\u003eGoodBots\u003c/span\u003e\u003c/a\u003e into the fediverse but this week I don\u0026#39;t have energy at the end of the day to implement any of them. Luckily the weekend is close 🙏 \u003ca href=\"https://hachyderm.io/tags/StayTuned\" class=\"mention hashtag\" rel=\"tag\"\u003e#\u003cspan\u003eStayTuned\u003c/span\u003e\u003c/a\u003e\u003c/p\u003e",
    "contentMap": {
        "en": "\u003cp\u003eI\u0026#39;m buzzing with ideas on how to bring all my \u003ca href=\"https://hachyderm.io/tags/GoodBots\" class=\"mention hashtag\" rel=\"tag\"\u003e#\u003cspan\u003eGoodBots\u003c/span\u003e\u003c/a\u003e into the fediverse but this week I don\u0026#39;t have energy at the end of the day to implement any of them. Luckily the weekend is close 🙏 \u003ca href=\"https://hachyderm.io/tags/StayTuned\" class=\"mention hashtag\" rel=\"tag\"\u003e#\u003cspan\u003eStayTuned\u003c/span\u003e\u003c/a\u003e\u003c/p\u003e"
    },
    "attachment": [],
    "tag": [
        {
            "type": "Hashtag",
            "href": "https://hachyderm.io/tags/GoodBots",
            "name": "#GoodBots"
        },
        {
            "type": "Hashtag",
            "href": "https://hachyderm.io/tags/staytuned",
            "name": "#staytuned"
        }
    ],
    "replies": {
        "id": "https://hachyderm.io/users/j3j5/statuses/109321328485360034/replies",
        "type": "Collection",
        "first": {
            "type": "CollectionPage",
            "next": "https://hachyderm.io/users/j3j5/statuses/109321328485360034/replies?min_id=109321387340611540\u0026page=true",
            "partOf": "https://hachyderm.io/users/j3j5/statuses/109321328485360034/replies",
            "items": [
                "https://hachyderm.io/users/j3j5/statuses/109321387340611540"
            ]
        }
    }
}

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.

2 participants