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

Schema with duplicate value causes infinite loop #87

Open
dochne opened this issue Jan 31, 2018 · 1 comment
Open

Schema with duplicate value causes infinite loop #87

dochne opened this issue Jan 31, 2018 · 1 comment

Comments

@dochne
Copy link

dochne commented Jan 31, 2018

If the @id of a schema and the value of another field (say, url) are identical, parsing the document will result in a stack overflow.

It looks like this is caused by Nodes being keyed by the value of the node, but I'm enough of a layman to be unsure as to:
a. whether there was a good reason to do it in the first place
b. if there is a good way to fix and
c. if it's even allowable by the JSON-LD spec (I would assume it is, but again, I'm not intricately familiar with it)

I'm willing to put in the effort to try and get this fixed, but I'd need some guidance about what should be done to do so.

Example JSON-LD:

{
  "@context": "http://schema.org/",
  "@type": "Website",
  "@id": "https://www.example.com/",
  "url": "https://www.example.com/"
}

Example test script:

include("vendor/autoload.php");

$class = new stdClass;
$class->{'@context'} = "http://schema.org/";
$class->{'@type'} = "Website";
$class->{'@id'} = "https://www.example.com/";
$class->{'url'} = "https://www.example.com/";

$graph = \ML\JsonLD\JsonLD::getDocument($class)->getGraph();

function iterateNodes(array $nodes, $maxDepth = 10, $prefix = "")
{
    if ($maxDepth === 0) {
        echo "Hit MaxDepth\n";
        return;
    }

    /**
     * @var \ML\JsonLD\Node $node
     */
    foreach ($nodes as $node) {
        echo $prefix . "ID: ".$node->getId()."\n";
        /**
         * @var \ML\JsonLD\Node[] $properties
         */
        $properties = $node->getProperties();
        iterateNodes($properties, $maxDepth - 1, $prefix . "  ");
    }
}

iterateNodes($graph->getNodes());

Expected output:

ID: https://www.example.com/
  ID: http://schema.org/Website
  ID: https://www.example.com
ID: http://schema.org/Website
ID: https://www.example.com/

Actual output:

ID: https://www.example.com/
  ID: http://schema.org/Website
  ID: https://www.example.com/
    ID: http://schema.org/Website
    ID: https://www.example.com/
      ID: http://schema.org/Website
      ID: https://www.example.com/
        ID: http://schema.org/Website
        ID: https://www.example.com/
          ID: http://schema.org/Website
          ID: https://www.example.com/
            ID: http://schema.org/Website
            ID: https://www.example.com/
              ID: http://schema.org/Website
              ID: https://www.example.com/
                ID: http://schema.org/Website
                ID: https://www.example.com/
                  ID: http://schema.org/Website
Hit MaxDepth
                  ID: https://www.example.com/
Hit MaxDepth
ID: http://schema.org/Website
@Sarke
Copy link

Sarke commented Mar 24, 2020

jkphl/micrometa#56

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

No branches or pull requests

2 participants