Skip to content

Commit

Permalink
markup: Allow arbitrary Asciidoc extension in unsafe mode
Browse files Browse the repository at this point in the history
  • Loading branch information
gzagatti committed Jan 11, 2021
1 parent 0004a73 commit 5ddfb6f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
3 changes: 1 addition & 2 deletions markup/asciidocext/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,10 @@ func (a *asciidocConverter) parseArgs(ctx converter.DocumentContext) []string {
args = a.appendArg(args, "-b", cfg.Backend, asciidocext_config.CliDefault.Backend, asciidocext_config.AllowedBackend)

for _, extension := range cfg.Extensions {
if !asciidocext_config.AllowedExtensions[extension] {
if cfg.SafeMode != "unsafe" && !asciidocext_config.AllowedExtensions[extension] {
a.cfg.Logger.Errorln("Unsupported asciidoctor extension was passed in. Extension `" + extension + "` ignored.")
continue
}

args = append(args, "-r", extension)
}

Expand Down
25 changes: 25 additions & 0 deletions markup/asciidocext/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,31 @@ func TestAsciidoctorDisallowedArgs(t *testing.T) {
c.Assert(args, qt.DeepEquals, expected)
}

func TestAsciidoctorArbitraryExtension(t *testing.T) {
c := qt.New(t)
cfg := viper.New()
mconf := markup_config.Default
mconf.AsciidocExt.Extensions = []string{"arbitrary-extension"}
p, err := Provider.New(
converter.ProviderConfig{
Cfg: cfg,
MarkupConfig: mconf,
Logger: loggers.NewErrorLogger(),
},
)
c.Assert(err, qt.IsNil)

conv, err := p.New(converter.DocumentContext{})
c.Assert(err, qt.IsNil)

ac := conv.(*asciidocConverter)
c.Assert(ac, qt.Not(qt.IsNil))

args := ac.parseArgs(converter.DocumentContext{})
expected := []string{"-r", "arbitrary-extension", "--no-header-footer"}
c.Assert(args, qt.DeepEquals, expected)
}

func TestAsciidoctorDiagramArgs(t *testing.T) {
c := qt.New(t)
cfg := viper.New()
Expand Down

0 comments on commit 5ddfb6f

Please sign in to comment.