From 77b64ecf1cf26af9def4cd6d63f0896d5f2c4c8e Mon Sep 17 00:00:00 2001 From: Marat Radchenko Date: Tue, 3 Mar 2020 20:38:54 +0300 Subject: [PATCH] resolves #281 prevent document from overriding epubcheck/kindlegen path attributes --- CHANGELOG.adoc | 1 + lib/asciidoctor-epub3/converter.rb | 9 +++++++++ spec/converter_spec.rb | 14 ++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 42a89a3a..ebb7b8d3 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -12,6 +12,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[ * add xref ids to paragraphs (#317) * support syntax highlighting with CodeRay and Rouge (#262) * pygments.rb is no longer auto-activated +* prevent document from overriding epubcheck/kindlegen path attributes (#281) == 1.5.0.alpha.14 (2020-02-29) - @slonopotamus diff --git a/lib/asciidoctor-epub3/converter.rb b/lib/asciidoctor-epub3/converter.rb index 0dbd1e14..96b603e8 100644 --- a/lib/asciidoctor-epub3/converter.rb +++ b/lib/asciidoctor-epub3/converter.rb @@ -97,6 +97,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['epubcheck-path'] ||= nil + attr_overrides['kindlegen-path'] ||= nil + end end def convert node, name = nil, _opts = {} diff --git a/spec/converter_spec.rb b/spec/converter_spec.rb index 9b746b5c..e4f83b7e 100644 --- a/spec/converter_spec.rb +++ b/spec/converter_spec.rb @@ -192,5 +192,19 @@ expect(book.publisher).not_to be_nil expect(book.publisher.content).to eq('MyProducer') end + + it 'prevents document from overriding kindlegen/epubcheck path attributes' do + book = to_epub <<~EOS += Article +:kindlegen-path: /evilgen +:epubcheck-path: /evilcheck + +{epubcheck-path} +{kindlegen-path} + EOS + + article = book.item_by_href '_article.xhtml' + expect(article.content).not_to include('evil') + end end end