diff --git a/lib/slime/parser.ex b/lib/slime/parser.ex index 8dbf88e..d9c37f4 100644 --- a/lib/slime/parser.ex +++ b/lib/slime/parser.ex @@ -14,9 +14,9 @@ defmodule Slime.Parser do @script "-" @smart "=" - @attr_delim_regex ~r/[ ]+(?=([^"]*"[^"]*")*[^"]*$)/ + @attr_delim_regex ~r/[ ]+(?=([^"]*"[^"]*")*[^"]*$)(?=(?:[^ "']+=|(?:allowfullscreen|async|autofocus|autoplay|checked|compact|controls|declare|default|defaultchecked|defaultmuted|defaultselected|defer|disabled|draggable|enabled|formnovalidate|hidden|indeterminate|inert|ismap|itemscope|loop|multiple|muted|nohref|noresize|noshade|novalidate|nowrap|open|pauseonexit|readonly|required|reversed|scoped|seamless|selected|sortable|spellcheck|translate|truespeed|typemustmatch|visible)(?: |$)))/ @attr_list_delims Application.get_env(:slime, :attr_list_delims, %{"{" => "}", "[" => "]", "(" => ")"}) - @attr_group_regex ~r/(?:\s*[\w-]+\s*=\s*(?:[^\s"'][^\s]+[^\s"']|"(?:(?\{(?:[^{}]|\g)*\})|[^"])*"|'[^']*'))*/ + @attr_group_regex ~r/(?:\s*[\w-]+\s*=\s*(?:[^"'].*?(?= [^ "']+=|$)|"(?:(?\{(?:[^{}]|\g)*\})|[^"])*"|'[^']*'))*/ @parse_line_split_regexes @attr_list_delims |> Dict.keys diff --git a/test/parser_test.exs b/test/parser_test.exs index 1a3a113..1f37646 100644 --- a/test/parser_test.exs +++ b/test/parser_test.exs @@ -95,6 +95,9 @@ defmodule ParserTest do {_, {"meta", opts}} = ~S(meta content=user["name"]) |> Parser.parse_line assert opts[:attributes] == [content: {:eex, content: ~S(user["name"]), inline: true}] + + {_, {"meta", opts}} = ~S[meta content=Module.function(param1, param2)] |> Parser.parse_line + assert opts[:attributes] == [content: {:eex, content: ~S[Module.function(param1, param2)], inline: true}] end test "parses attributes and inline children" do diff --git a/test/rendering/attributes_test.exs b/test/rendering/attributes_test.exs index fcf1f5c..532cec2 100644 --- a/test/rendering/attributes_test.exs +++ b/test/rendering/attributes_test.exs @@ -54,12 +54,12 @@ defmodule RenderAttributesTest do end test "rendering of boolean attributes" do - assert render(~s(div [ab="ab" a] a)) == ~s(
a
) - assert render(~s(div [a b="b"] c)) == ~s(
c
) + assert render(~s(div [ab="ab" hidden] a)) == ~s() + assert render(~s(div [hidden b="b"] c)) == ~s() assert render(~S(div ab="#{b} a" a), b: "b") == ~s(
a
) - assert render(~S(div[ab="a #{b}" a] a), b: "b") == ~s(
a
) - assert render(~S, b: &(&1)) == ~s(
a
) - assert render(~S, b: fn {_, r} -> r end) == ~s(
a
) + assert render(~S(div[ab="a #{b}" hidden] a), b: "b") == ~s() + assert render(~S, b: &(&1)) == ~s() + assert render(~S, b: fn {_, r} -> r end) == ~s() assert render(~s(script[defer async src="..."])) == ~s() end