diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-07-21 12:41:23 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-07-21 12:41:23 +0300 |
commit | ff16c42ed0965e1c8acf6e6a6dcda3ea50c107f2 (patch) | |
tree | da1290397767bc9233b90e38230d8502dd975f10 | |
parent | 166483fe1227b0c59c6b4d88cfdfaf7d7b0d79c5 (diff) |
hugolib: Allow untyped nil to be merged in lang.Merge
Fixes #4977
-rw-r--r-- | hugolib/pages_language_merge.go | 3 | ||||
-rw-r--r-- | hugolib/pages_language_merge_test.go | 5 |
2 files changed, 8 insertions, 0 deletions
diff --git a/hugolib/pages_language_merge.go b/hugolib/pages_language_merge.go index 6e467c7a0..ef87ac9cb 100644 --- a/hugolib/pages_language_merge.go +++ b/hugolib/pages_language_merge.go @@ -53,6 +53,9 @@ func (p1 Pages) MergeByLanguage(p2 Pages) Pages { // 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) diff --git a/hugolib/pages_language_merge_test.go b/hugolib/pages_language_merge_test.go index b7c78836c..8a4688f16 100644 --- a/hugolib/pages_language_merge_test.go +++ b/hugolib/pages_language_merge_test.go @@ -79,6 +79,11 @@ func TestMergeLanguages(t *testing.T) { // 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) { |