Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/better_html/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def build_attribute_value_node(tokens)
:attribute_unquoted_value,
)

build_node(:attribute_value, children)
build_node(:attribute_value, children) if children.any?
end

def build_text_node(tokens)
Expand Down
31 changes: 31 additions & 0 deletions test/better_html/parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,37 @@ class ParserTest < ActiveSupport::TestCase
tree.ast
end

test "consumes tag attributes without value" do
tree = Parser.new(buffer("<div foo=>bar</div>"))
assert_equal s(
:document,
s(
:tag,
nil,
s(:tag_name, "div"),
s(
:tag_attributes,
s(
:attribute,
s(:attribute_name, "foo"),
s(:equal),
nil,
),
),
nil,
),
s(:text, "bar"),
s(
:tag,
s(:solidus),
s(:tag_name, "div"),
nil,
nil,
),
),
tree.ast
end

test "consume tag attributes nodes interpolation in name and value" do
tree = Parser.new(buffer("<div data-<%= foo %>=\"some <%= value %> foo\">"))
assert_equal s(
Expand Down
Loading