summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2022-09-10 23:45:21 -0600
committerGitHub <noreply@github.com>2022-09-10 23:45:21 -0600
commit07915e1d7ea94fb554d11487e18478cddb2db02f (patch)
tree88638ef60cc6912e251d624970730c936f548e6a /lib
parent6c56c809986cb67e76f865ef324e5ff35ce5b850 (diff)
resolves #4351 force encoding of attribute data passed via CLI to UTF-8 if transcoding fails (PR #4354)
Diffstat (limited to 'lib')
-rw-r--r--lib/asciidoctor/cli/options.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/asciidoctor/cli/options.rb b/lib/asciidoctor/cli/options.rb
index e3e0119f..bc4e46c6 100644
--- a/lib/asciidoctor/cli/options.rb
+++ b/lib/asciidoctor/cli/options.rb
@@ -91,7 +91,11 @@ module Asciidoctor
'unless either the name or value ends in @ (i.e., name@=value or name=value@)',
'may be specified more than once' do |attr|
next if (attr = attr.rstrip).empty? || attr == '='
- attr = attr.encode UTF_8 unless attr.encoding == UTF_8
+ begin
+ attr = attr.encode UTF_8
+ rescue ::EncodingError
+ attr = attr.force_encoding UTF_8
+ end unless attr.encoding == UTF_8
name, _, val = attr.partition '='
self[:attributes][name] = val
end