Skip to content
This repository was archived by the owner on Feb 10, 2026. It is now read-only.

Commit d74c923

Browse files
committed
Fix for naked attributes
1 parent c2aa4d6 commit d74c923

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎lib/live_view_native/template/parser.ex‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,9 @@ defmodule LiveViewNative.Template.Parser do
363363
{:error, "unexpected end of file while parsing attribute name", [start: cursor, end: cursor]}
364364
end
365365

366-
defp parse_attribute_name(<<char::utf8, _document::binary>>, cursor, _buffer, _args) do
367-
{:error, "invalid character in attribute name: #{[char]}", [start: cursor, end: cursor]}
366+
defp parse_attribute_name(<<char::utf8, _document::binary>>, cursor, name_buffer, _args) do
367+
name = List.to_string(name_buffer)
368+
{:error, "invalid character: #{<<char::utf8>>} in attribute name: #{name}", [start: cursor, end: cursor]}
368369
end
369370

370371
defp parse_attribute_assignment(<<char::utf8, document::binary>>, cursor, name, args) when char in @whitespace do
@@ -379,6 +380,14 @@ defmodule LiveViewNative.Template.Parser do
379380
{:boolean, {document, name, cursor}}
380381
end
381382

383+
defp parse_attribute_assignment(<<"/>"::utf8, _document::binary>> = document, cursor, name, _args) do
384+
{:boolean, {document, name, cursor}}
385+
end
386+
387+
defp parse_attribute_assignment(<<">"::utf8, _document::binary>> = document, cursor, name, _args) do
388+
{:boolean, {document, name, cursor}}
389+
end
390+
382391
defp parse_attribute_assignment(<<char::utf8, _document::binary>>, cursor, name, _args) do
383392
{:error, "invalid character: #{<<char::utf8>>} in attribute name: #{name}", [start: cursor, end: cursor]}
384393
end

‎test/live_view_native/template/parser_test.exs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,15 @@ defmodule LiveViewNative.Template.ParserTest do
5959
test "will parse boolean attribute" do
6060
{:ok, nodes} = """
6161
<FooBar a="1" b c="true"/>
62+
<Baz a></Baz>
63+
<Qux b/>
6264
"""
6365
|> parse_document()
6466

6567
assert nodes == [
66-
{"FooBar", [{"a", "1"}, {"b", "b"}, {"c", "true"}], []}
68+
{"FooBar", [{"a", "1"}, {"b", "b"}, {"c", "true"}], []},
69+
{"Baz", [{"a", "a"}], []},
70+
{"Qux", [{"b", "b"}], []}
6771
]
6872
end
6973

0 commit comments

Comments
 (0)