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

Recursive loop when ID is the same as URL #29

Closed
dochne opened this issue Jan 25, 2018 · 8 comments · Fixed by #56
Closed

Recursive loop when ID is the same as URL #29

dochne opened this issue Jan 25, 2018 · 8 comments · Fixed by #56
Assignees
Labels

Comments

@dochne
Copy link

dochne commented Jan 25, 2018

Example code:

<?php
include("vendor/autoload.php");
$jsonld = <<<EOF
<script type="application/ld+json">
{
  "@context": "http://schema.org/",
  "@type": "Website",
  "@id": "https://www.example.com/",
  "url": "https://www.example.com/"
}
</script>
EOF;

$parser = new \Jkphl\Micrometa\Ports\Parser();
$parser("https://www.example.com/", $jsonld);

If url is changed to omit the final backslash, it works fine. I'm assuming this is related to issue #27. I'm attempting to put together a PR to fix it but I'm ending up a little lost, any advice you can give as to what the most likely cause would be appreciated.

@dochne
Copy link
Author

dochne commented Jan 26, 2018

This looks like it's a bug in the underlying JSON-LD library.

@jkphl jkphl self-assigned this Jan 26, 2018
@jkphl jkphl added the question label Jan 26, 2018
@jkphl
Copy link
Owner

jkphl commented Jan 26, 2018

@Dolondro Sorry I didn't have the time to test the issue and reply yet. But yes, it looks like this is very likely — micrometa basically wraps around the JSON-LD parser, adds some functionality and unifies the output across the different formats. As soon as I find some time I'll try to further look into this ...

@dochne
Copy link
Author

dochne commented Jan 26, 2018

Hiya, thanks for getting back to me.

It looks like the issue is in Processor.php -> generateNodeMap. It looks like they're keying the node map by the values, hence the collision and the infinite loop.

I'll write a test case and submit it as a Issue with them, but it looks suspiciously like they may have ceased bothering with the project :(

@jkphl
Copy link
Owner

jkphl commented Jan 26, 2018

@Dolondro You might be right, unfortunately. AFAIK it's mostly one guy who wrote it, and I read a statement somewhere a while ago that he doesn't plan to put a lot more effort into it. And AFAIR there was one other library doing basically the same thing but had a comparably ugly API / was harder to work with ... Please let me know if you're lucky with your issue or find a viable alternative. Thanks!

@dochne
Copy link
Author

dochne commented Jan 31, 2018

Bug report for the underlying issue can be found here: lanthaler/JsonLD#87

@rvanlaak
Copy link
Collaborator

@jkphl https://github.com/digitalbazaar/php-json-ld is the other library you were referring to?

@jkphl
Copy link
Owner

jkphl commented Nov 1, 2019

@rvanlaak Exactly! Unfortunately, there's no news on the upstream error (lanthaler/JsonLD#87) and the API of php-json-ld is still as ugly as 2 years ago. :(

When I decided to build on an external JSON-LD parser I briefly looked into rolling my own, but JSON-LD parsing is far from being trivial, so I decided to focus on what's more important for me (JSON-LD was never a high priority thing for me ...)

@Sarke
Copy link
Contributor

Sarke commented Nov 28, 2019

Isn't this just a matter of implementation? If an entity wants to reference itself, or have a child reference the parent, it can do so. Any var dumper will have to solve this problem.

That is, what lanthaler/JsonLD returns is correct, you just have to be careful when you start looping through it not to end up in an endless loop.

Sarke added a commit to Sarke/micrometa that referenced this issue Mar 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants