Skip to content

Commit

Permalink
resolves asciidoctor#4033 don't assign nil value to named attribute m…
Browse files Browse the repository at this point in the history
…apped to absent positional attribute when parsing attrlist
  • Loading branch information
mojavelinux committed Apr 22, 2021
1 parent 5c7be5e commit b3e45cd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.adoc
Expand Up @@ -13,6 +13,12 @@ endif::[]
This document provides a high-level view of the changes introduced in Asciidoctor by release.
For a detailed view of what has changed, refer to the {uri-repo}/commits/master[commit history] on GitHub.

== Unreleased

Bug Fixes::

* Don't assign nil value to named attribute mapped to absent positional attribute when parsing attrlist (#4033)

// tag::compact[]
== 2.0.14 (2021-04-19) - @mojavelinux

Expand Down
2 changes: 1 addition & 1 deletion lib/asciidoctor/attribute_list.rb
Expand Up @@ -173,7 +173,7 @@ def parse_attribute index, positional_attrs
end
else
name = @block.apply_subs name if single_quoted && @block
if (positional_attr_name = positional_attrs[index])
if (positional_attr_name = positional_attrs[index]) && name
@attributes[positional_attr_name] = name
end
# QUESTION should we assign the positional key even when it's claimed by a positional attribute?
Expand Down
5 changes: 2 additions & 3 deletions test/attribute_list_test.rb
Expand Up @@ -262,11 +262,10 @@ def doc.apply_subs *args
assert_equal expected, attributes
end

# FIXME this is a negative test that should be updated when the problem is fixed
test 'should assign nil to attribute mapped to missing positional attribute' do
test 'should not assign nil to attribute mapped to missing positional attribute' do
attributes = {}
line = 'alt text,,100'
expected = { 1 => 'alt text', 2 => nil, 3 => '100', 'alt' => 'alt text', 'width' => nil, 'height' => '100' }
expected = { 1 => 'alt text', 2 => nil, 3 => '100', 'alt' => 'alt text', 'height' => '100' }
Asciidoctor::AttributeList.new(line).parse_into(attributes, %w(alt width height))
assert_equal expected, attributes
end
Expand Down
6 changes: 3 additions & 3 deletions test/blocks_test.rb
Expand Up @@ -2590,11 +2590,11 @@ def names
assert_xpath '/*[@class="imageblock"]//img[@src="images/tiger.png"][@alt="Tiger"][@width="200"][@height="300"]', output, 1
end

# FIXME this is a negative test that should be updated when the problem is fixed
test 'should output empty width attribute if positional width attribute is empty' do
test 'should not output empty width attribute if positional width attribute is empty' do
input = 'image::images/tiger.png[Tiger,]'
output = convert_string_to_embedded input
assert_xpath '/*[@class="imageblock"]//img[@src="images/tiger.png"][@width=""]', output, 1
assert_xpath '/*[@class="imageblock"]//img[@src="images/tiger.png"]', output, 1
assert_xpath '/*[@class="imageblock"]//img[@src="images/tiger.png"][@width]', output, 0
end

test "can convert block image with link" do
Expand Down

0 comments on commit b3e45cd

Please sign in to comment.