mirror of
https://github.com/gohugoio/hugo.git
synced 2025-05-04 09:31:46 +03:00
Prevent cyclic ref crash in JSON encode
Note that this commit makes no promise about great JSON output from the encoder, but the cyclic refs should be broken. Fixes #1123
This commit is contained in:
parent
be778c3160
commit
be7c3bbb09
4 changed files with 35 additions and 3 deletions
|
@ -22,7 +22,7 @@ import (
|
||||||
|
|
||||||
type Node struct {
|
type Node struct {
|
||||||
RSSLink template.HTML
|
RSSLink template.HTML
|
||||||
Site *SiteInfo
|
Site *SiteInfo `json:"-"`
|
||||||
// layout string
|
// layout string
|
||||||
Data map[string]interface{}
|
Data map[string]interface{}
|
||||||
Title string
|
Title string
|
||||||
|
|
|
@ -71,7 +71,7 @@ type Page struct {
|
||||||
renderingConfigInit sync.Once
|
renderingConfigInit sync.Once
|
||||||
PageMeta
|
PageMeta
|
||||||
Source
|
Source
|
||||||
Position
|
Position `json:"-"`
|
||||||
Node
|
Node
|
||||||
pageMenus PageMenus
|
pageMenus PageMenus
|
||||||
pageMenusInit sync.Once
|
pageMenusInit sync.Once
|
||||||
|
|
|
@ -79,7 +79,7 @@ type Site struct {
|
||||||
timer *nitro.B
|
timer *nitro.B
|
||||||
Targets targetList
|
Targets targetList
|
||||||
targetListInit sync.Once
|
targetListInit sync.Once
|
||||||
Completed chan bool
|
Completed chan bool `json:"-"`
|
||||||
RunMode runmode
|
RunMode runmode
|
||||||
params map[string]interface{}
|
params map[string]interface{}
|
||||||
draftCount int
|
draftCount int
|
||||||
|
|
32
hugolib/siteJSONEncode_test.go
Normal file
32
hugolib/siteJSONEncode_test.go
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
package hugolib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Issue #1123
|
||||||
|
// Testing prevention of cyclic refs in JSON encoding
|
||||||
|
// May be smart to run with: -timeout 4000ms
|
||||||
|
func TestEncodePage(t *testing.T) {
|
||||||
|
|
||||||
|
// borrowed from menu_test.go
|
||||||
|
s := createTestSite(MENU_PAGE_SOURCES)
|
||||||
|
testSiteSetup(s, t)
|
||||||
|
|
||||||
|
j, err := json.Marshal(s)
|
||||||
|
check(t, err)
|
||||||
|
fmt.Println("Site as JSON", string(j))
|
||||||
|
|
||||||
|
p, err := json.Marshal(s.Pages[0])
|
||||||
|
check(t, err)
|
||||||
|
fmt.Println("Page as JSON", string(p))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func check(t *testing.T, err error) {
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed %s", err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue