diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 020e9f6e..489124f5 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -10,6 +10,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[ * fix chapter titles to actually be chapter titles instead of document title (#343) * store syntax highlighter CSS in a separate file (#339) * initial landmarks support: appendix, bibliography, bodymatter, cover, frontmatter, glossary, index, preface, toc (#174) +* prevent document from overriding epubcheck/kindlegen path attributes (#281) == 1.5.0.alpha.17 (2020-05-25) - @slonopotamus diff --git a/lib/asciidoctor-epub3/converter.rb b/lib/asciidoctor-epub3/converter.rb index 71605aae..4fab9ca2 100644 --- a/lib/asciidoctor-epub3/converter.rb +++ b/lib/asciidoctor-epub3/converter.rb @@ -98,6 +98,15 @@ def initialize backend, opts = {} basebackend 'html' outfilesuffix '.epub' # dummy outfilesuffix since it may be .mobi htmlsyntax 'xml' + + attr_overrides = opts[:document].instance_variable_get :@attribute_overrides + if attr_overrides.nil? + logger.error 'Failed to prevent document from overriding epubcheck/kindlegen path attributes' + else + # Prevent document fro overriding paths to binaries that we execute + attr_overrides['ebook-epubcheck-path'] ||= nil + attr_overrides['ebook-kindlegen-path'] ||= nil + end end def convert node, name = nil, _opts = {} diff --git a/spec/converter_spec.rb b/spec/converter_spec.rb index 306c3a3f..04b3e6b5 100644 --- a/spec/converter_spec.rb +++ b/spec/converter_spec.rb @@ -328,5 +328,19 @@ EOS end + + it 'prevents document from overriding kindlegen/epubcheck path attributes' do + book = to_epub <<~EOS += Article +:ebook-kindlegen-path: /evilgen +:ebook-epubcheck-path: /evilcheck + +{ebook-epubcheck-path} +{ebook-kindlegen-path} + EOS + + article = book.item_by_href '_article.xhtml' + expect(article.content).not_to include('evil') + end end end