1// +build gofuzz 2 3// Copyright 2021 Google LLC 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// 9// http://www.apache.org/licenses/LICENSE-2.0 10// 11// Unless required by applicable law or agreed to in writing, software 12// distributed under the License is distributed on an "AS IS" BASIS, 13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14// See the License for the specific language governing permissions and 15// limitations under the License. 16 17package transform 18 19import ( 20 "github.com/gohugoio/hugo/common/loggers" 21 "github.com/gohugoio/hugo/config" 22 "github.com/gohugoio/hugo/deps" 23 "github.com/gohugoio/hugo/helpers" 24 "github.com/gohugoio/hugo/hugofs" 25 "github.com/gohugoio/hugo/langs" 26 "github.com/spf13/afero" 27 "github.com/spf13/viper" 28) 29 30func newFuzzDeps(cfg config.Provider) *deps.Deps { 31 cfg.Set("contentDir", "content") 32 cfg.Set("i18nDir", "i18n") 33 34 l := langs.NewLanguage("en", cfg) 35 36 cs, _ := helpers.NewContentSpec(l, loggers.NewErrorLogger(), afero.NewMemMapFs()) 37 38 return &deps.Deps{ 39 Cfg: cfg, 40 Fs: hugofs.NewMem(l), 41 ContentSpec: cs, 42 } 43} 44 45func FuzzMarkdownify(data []byte) int { 46 v := viper.New() 47 v.Set("contentDir", "content") 48 ns := New(newFuzzDeps(v)) 49 50 for _, test := range []struct { 51 s interface{} 52 }{ 53 {string(data)}, 54 } { 55 _, err := ns.Markdownify(test.s) 56 if err != nil { 57 return 0 58 } 59 } 60 return 1 61} 62