Skip to content

Commit

Permalink
fix: Ignore nil elements from array attribute parsing (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephannv authored Sep 4, 2023
1 parent 6a06ef2 commit 3fb5269
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions spec/blueprint/html/attributes_parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ private class DummyPage
section(v_model: "user.name", "@click": "doSomething") { "Transform attribute name" }
input(disabled: true, checked: false, outline: "true", border: "false")
nav(aria: {target: "#home", selected: "false", enabled: true, hidden: false}) { "Nested attributes" }
div(class: ["a", "b", ["c", "d"]]) { "Array attributes" }
div(class: ["a", nil, "b", ["c", nil, "d"]]) { "Array attributes" }
end
end

Expand Down Expand Up @@ -59,7 +59,7 @@ describe "Blueprint::HTML attributes parser" do
page.to_html.should contain(nav)
end

it "flattens and joins array attributes" do
it "flattens, compacts and joins array attributes" do
page = DummyPage.new
nav = <<-HTML.strip
<div class="a b c d">Array attributes</div>
Expand Down
2 changes: 1 addition & 1 deletion src/blueprint/html/attributes_parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module Blueprint::HTML
end

private def append_array_attribute(io : String::Builder, attribute_name, attribute_value : Array) : Nil
append_normal_attribute(io, attribute_name, attribute_value.flatten.join(" "))
append_normal_attribute(io, attribute_name, attribute_value.flatten.compact.join(" "))
end

private def process_named_tuple_attribute(io : String::Builder, attribute_name, attribute_value : NamedTuple) : Nil
Expand Down

0 comments on commit 3fb5269

Please sign in to comment.