summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2023-10-12 01:40:09 -0600
committerGitHub <noreply@github.com>2023-10-12 01:40:09 -0600
commit7e34ca0be2fb6329655d6e3d86824ff1e9af4675 (patch)
treeab7287dcc30ddc59f69a0d54837ddf8d601710d2
parent1d569e79d1e3d57608f4a338cd9976977232f13e (diff)
resolves #3526 return nil if name passed to Asciidoctor::SafeMode.value_for_name is not recognized (PR #4496)
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor.rb2
-rw-r--r--lib/asciidoctor/document.rb2
-rw-r--r--test/api_test.rb10
4 files changed, 13 insertions, 2 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 414322b4..82a9fbd2 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -62,6 +62,7 @@ Improvements::
* Add single and double role hint to `<quote>` tag in DocBook output (#2947)
* Use safe navigation to avoid crashing when querying for extensions
* Remove empty line at top of table cells in manpage output (#4482) (*@strager*)
+ * Return `nil` if name passed to `Asciidoctor::SafeMode.value_for_name` is not recognized (#3526)
Bug Fixes::
diff --git a/lib/asciidoctor.rb b/lib/asciidoctor.rb
index 45c28f6a..386b90c4 100644
--- a/lib/asciidoctor.rb
+++ b/lib/asciidoctor.rb
@@ -92,7 +92,7 @@ module Asciidoctor
@names_by_value = (constants false).map {|sym| [(const_get sym), sym.to_s.downcase] }.sort {|(a), (b)| a <=> b }.to_h
def self.value_for_name name
- const_get name.upcase, false
+ const_get name.upcase, false rescue nil
end
def self.name_for_value value
diff --git a/lib/asciidoctor/document.rb b/lib/asciidoctor/document.rb
index af5fb51d..71fb887a 100644
--- a/lib/asciidoctor/document.rb
+++ b/lib/asciidoctor/document.rb
@@ -323,7 +323,7 @@ class Document < AbstractBlock
# be permissive in case API user wants to define new levels
@safe = safe_mode
else
- @safe = (SafeMode.value_for_name safe_mode) rescue SafeMode::SECURE
+ @safe = (SafeMode.value_for_name safe_mode) || SafeMode::SECURE
end
input_mtime = options.delete :input_mtime
@compat_mode = attr_overrides.key? 'compat-mode'
diff --git a/test/api_test.rb b/test/api_test.rb
index 02e93c08..91839bbf 100644
--- a/test/api_test.rb
+++ b/test/api_test.rb
@@ -2078,4 +2078,14 @@ context 'API' do
refute doc.blocks[1].sections?
end
end
+
+ context 'SafeMode' do
+ test 'should return nil if safe mode value not recognized' do
+ assert_nil Asciidoctor::SafeMode.name_for_value 99
+ end
+
+ test 'should return nil if safe mode name not recognized' do
+ assert_nil Asciidoctor::SafeMode.value_for_name 'unknown'
+ end
+ end
end