shithub: hugo

Download patch

ref: ff16c42ed0965e1c8acf6e6a6dcda3ea50c107f2
parent: 166483fe1227b0c59c6b4d88cfdfaf7d7b0d79c5
author: Bjørn Erik Pedersen <[email protected]>
date: Sat Jul 21 07:41:23 EDT 2018

hugolib: Allow untyped nil to be merged in lang.Merge

Fixes #4977

--- a/hugolib/pages_language_merge.go
+++ b/hugolib/pages_language_merge.go
@@ -53,6 +53,9 @@
 // MergeByLanguageInterface is the generic version of MergeByLanguage. It
 // is here just so it can be called from the tpl package.
 func (p1 Pages) MergeByLanguageInterface(in interface{}) (interface{}, error) {
+	if in == nil {
+		return p1, nil
+	}
 	p2, ok := in.(Pages)
 	if !ok {
 		return nil, fmt.Errorf("%T cannot be merged by language", in)
--- a/hugolib/pages_language_merge_test.go
+++ b/hugolib/pages_language_merge_test.go
@@ -79,6 +79,11 @@
 	// This looks less ugly in the templates ...
 	mergedNNResources := ri.(resource.ResourcesLanguageMerger).MergeByLanguage(enBundle.Resources)
 	assert.Equal(6, len(mergedNNResources))
+
+	unchanged, err := nnSite.RegularPages.MergeByLanguageInterface(nil)
+	assert.NoError(err)
+	assert.Equal(nnSite.RegularPages, unchanged)
+
 }
 
 func TestMergeLanguagesTemplate(t *testing.T) {