{"action":"created","issue":{"url":"https://api.github.com/repos/iand/microdata/issues/3","repository_url":"https://api.github.com/repos/iand/microdata","labels_url":"https://api.github.com/repos/iand/microdata/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/iand/microdata/issues/3/comments","events_url":"https://api.github.com/repos/iand/microdata/issues/3/events","html_url":"https://github.com/iand/microdata/issues/3","id":360255754,"node_id":"MDU6SXNzdWUzNjAyNTU3NTQ=","number":3,"title":"Fatal stack overflow with malformed microdata","user":{"login":"mcnijman","id":888707,"node_id":"MDQ6VXNlcjg4ODcwNw==","avatar_url":"https://avatars0.githubusercontent.com/u/888707?v=4","gravatar_id":"","url":"https://api.github.com/users/mcnijman","html_url":"https://github.com/mcnijman","followers_url":"https://api.github.com/users/mcnijman/followers","following_url":"https://api.github.com/users/mcnijman/following{/other_user}","gists_url":"https://api.github.com/users/mcnijman/gists{/gist_id}","starred_url":"https://api.github.com/users/mcnijman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcnijman/subscriptions","organizations_url":"https://api.github.com/users/mcnijman/orgs","repos_url":"https://api.github.com/users/mcnijman/repos","events_url":"https://api.github.com/users/mcnijman/events{/privacy}","received_events_url":"https://api.github.com/users/mcnijman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-14T10:51:57Z","updated_at":"2018-09-14T10:58:51Z","closed_at":null,"author_association":"NONE","body":"I'm parsing an extract of the common crawl and stumbled upon an html response that has malformed microdata. In this instance the `itemref` property is referencing itself. Because of this stack overflow happens due to https://github.com/iand/microdata/blob/master/microdata.go#L171 calling itself infinitely.\r\n\r\nReproducible with:\r\n```go\r\nhtml := []byte(`\r\n<body itemscope itemtype=\"http://schema.org/WebPage\">\r\n\t<span id=\"1\" itemscope itemtype=\"http://data-vocabulary.org/Breadcrumb\" itemprop=\"child\" itemref=\"1\">\r\n\t\t<a title=\"Foo\" itemprop=\"url\" href=\"/foo/bar\"><span itemprop=\"title\">Foo</span></a>\r\n\t</span>\r\n</body>`)\r\n\r\np := microdata.NewParser(\r\n\tbytes.NewReader(html),\r\n\t&url.URL{Scheme: \"https\", Host: \"foo.bar\"},\r\n)\r\n\r\np.Parse()\r\n```\r\n\r\nAs a stack overflow is definitely undesirable, I think the solution would either be to return an error or just skip this node. Skipping a self referencing node could be achieved by replacing https://github.com/iand/microdata/blob/master/microdata.go#L171 with:\r\n```go\r\nif refnode != node {\r\n\tp.readItem(subitem, refnode)\r\n}\r\n```\r\n\r\nLet me know what you think. I'll be able to prepare a pull request with a test case."},"comment":{"url":"https://api.github.com/repos/iand/microdata/issues/comments/421321891","html_url":"https://github.com/iand/microdata/issues/3#issuecomment-421321891","issue_url":"https://api.github.com/repos/iand/microdata/issues/3","id":421321891,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMTMyMTg5MQ==","user":{"login":"iand","id":18375,"node_id":"MDQ6VXNlcjE4Mzc1","avatar_url":"https://avatars1.githubusercontent.com/u/18375?v=4","gravatar_id":"","url":"https://api.github.com/users/iand","html_url":"https://github.com/iand","followers_url":"https://api.github.com/users/iand/followers","following_url":"https://api.github.com/users/iand/following{/other_user}","gists_url":"https://api.github.com/users/iand/gists{/gist_id}","starred_url":"https://api.github.com/users/iand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iand/subscriptions","organizations_url":"https://api.github.com/users/iand/orgs","repos_url":"https://api.github.com/users/iand/repos","events_url":"https://api.github.com/users/iand/events{/privacy}","received_events_url":"https://api.github.com/users/iand/received_events","type":"User","site_admin":false},"created_at":"2018-09-14T10:58:51Z","updated_at":"2018-09-14T10:58:51Z","author_association":"OWNER","body":"Looks good. I'll accept any pull request with a test."}}
{"actor":{"display_login":"iand"}}