diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2022-03-20 21:24:56 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-20 21:24:56 -0600 |
| commit | 0aad7459d1fe548219733b4a2b4f00fd3bf6f362 (patch) | |
| tree | 3e1d67c44b1701d97ffd9f7ba902267ee5267cc7 | |
| parent | cabac9c30e660b77e8b87a98587a773defc314c8 (diff) | |
resolves #420 don't raise error if Asciidoctor::Extensions.unregister is called before groups are initialized (PR #4271)
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/extensions.rb | 2 | ||||
| -rw-r--r-- | test/extensions_test.rb | 13 |
3 files changed, 15 insertions, 1 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 0743514a..aa4f590b 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -54,6 +54,7 @@ Improvements:: Bug Fixes:: + * Don't raise error if `Asciidoctor::Extensions.unregister` is called before groups are initialized * If path is included both partially and fully, store it with true value (included fully) in includes table of document catalog * Reset registry if activate is called on it again (#4256) * Format source location in exception message when extension code is malformed diff --git a/lib/asciidoctor/extensions.rb b/lib/asciidoctor/extensions.rb index 194b3ea9..3ed02088 100644 --- a/lib/asciidoctor/extensions.rb +++ b/lib/asciidoctor/extensions.rb @@ -1531,7 +1531,7 @@ module Extensions # # Returns nothing def unregister *names - names.each {|group| @groups.delete group.to_sym } + names.each_with_object(groups) {|group, catalog| catalog.delete group.to_sym } nil end end diff --git a/test/extensions_test.rb b/test/extensions_test.rb index 8a2632c1..f37ad635 100644 --- a/test/extensions_test.rb +++ b/test/extensions_test.rb @@ -345,6 +345,19 @@ context 'Extensions' do end end + test 'should not fail to unregister extension group if not registered' do + refute_nil Asciidoctor::Extensions.groups + assert_equal 0, Asciidoctor::Extensions.groups.size + Asciidoctor::Extensions.unregister :sample + assert_equal 0, Asciidoctor::Extensions.groups.size + end + + test 'should not fail to unregister extension group if extension groups are not initialized' do + Asciidoctor::Extensions.remove_instance_variable :@groups + Asciidoctor::Extensions.unregister :sample + assert_equal 0, Asciidoctor::Extensions.groups.size + end + test 'should raise NameError if extension class cannot be resolved from string' do begin Asciidoctor::Extensions.register do |
