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) 28 29func newFuzzDeps(cfg config.Provider) *deps.Deps { 30 cfg.Set("contentDir", "content") 31 cfg.Set("i18nDir", "i18n") 32 33 l := langs.NewLanguage("en", cfg) 34 35 cs, _ := helpers.NewContentSpec(l, loggers.NewErrorLogger(), afero.NewMemMapFs()) 36 37 return &deps.Deps{ 38 Cfg: cfg, 39 Fs: hugofs.NewMem(l), 40 ContentSpec: cs, 41 } 42} 43 44func FuzzMarkdownify(data []byte) int { 45 v := config.New() 46 v.Set("contentDir", "content") 47 ns := New(newFuzzDeps(v)) 48 49 for _, test := range []struct { 50 s interface{} 51 }{ 52 {string(data)}, 53 } { 54 _, err := ns.Markdownify(test.s) 55 if err != nil { 56 return 0 57 } 58 } 59 return 1 60} 61