Fix #3: fatal stack overflow
parent
2dfc019ddc
commit
c529673a50
|
@ -167,7 +167,9 @@ func (p *Parser) readItem(item *Item, node *html.Node) {
|
||||||
itemref = strings.TrimSpace(itemref)
|
itemref = strings.TrimSpace(itemref)
|
||||||
|
|
||||||
if refnode, exists := p.identifiedNodes[itemref]; exists {
|
if refnode, exists := p.identifiedNodes[itemref]; exists {
|
||||||
p.readItem(subitem, refnode)
|
if refnode != node {
|
||||||
|
p.readItem(subitem, refnode)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ package microdata
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -569,3 +570,30 @@ func TestJsonWithType(t *testing.T) {
|
||||||
t.Errorf("Expecting %s but got %s", expected, actual)
|
t.Errorf("Expecting %s but got %s", expected, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This test checks stack overflow doesn't happen as mentioned in
|
||||||
|
// https://github.com/iand/microdata/issues/3
|
||||||
|
func TestSkipSelfReferencingItemref(t *testing.T) {
|
||||||
|
html := `<body itemscope itemtype="http://schema.org/WebPage">
|
||||||
|
<span id="1" itemscope itemtype="http://data-vocabulary.org/Breadcrumb" itemprop="child" itemref="1">
|
||||||
|
<a title="Foo" itemprop="url" href="/foo/bar"><span itemprop="title">Foo</span></a>
|
||||||
|
</span>
|
||||||
|
</body>`
|
||||||
|
|
||||||
|
actual := ParseData(html, t)
|
||||||
|
|
||||||
|
child := NewItem()
|
||||||
|
child.AddString("title", "Foo")
|
||||||
|
child.AddString("url", "http://example.com/foo/bar")
|
||||||
|
|
||||||
|
item := NewItem()
|
||||||
|
item.AddType("http://schema.org/WebPage")
|
||||||
|
item.AddItem("child", child)
|
||||||
|
|
||||||
|
expected := NewMicrodata()
|
||||||
|
expected.AddItem(item)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(expected, actual) {
|
||||||
|
t.Errorf("Expecting %s but got %s", expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue