From d310076abde47b45a5926d05200506ac635f5284 Mon Sep 17 00:00:00 2001 From: Leandro Pereira Date: Tue, 10 Sep 2024 10:05:17 -0400 Subject: [PATCH] HEEx Decoder - handle attr values with `nil` values This should close the issue https://github.com/BeaconCMS/beacon_live_admin/issues/226 --- CHANGELOG.md | 1 + lib/beacon/template/heex/heex_decoder.ex | 4 ++++ test/beacon/template/heex/heex_decoder_test.exs | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfd422c9b..2fbd41a3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * [Media Library] Guard against invalid values for `:sort` option in `MediaLibrary.list_assets/2` * [Content] Guard against invalid values for `:sort` option in `Content.list_layouts/2` * [Content] Guard against invalid values for `:sort` option in `Content.list_pages/2` + * [HEEx Decoder] Handle attr values with `nil` values, for example the `defer` in script tags ## 0.1.0-rc.1 (2024-08-27) diff --git a/lib/beacon/template/heex/heex_decoder.ex b/lib/beacon/template/heex/heex_decoder.ex index 14843e6ee..82bc864ce 100644 --- a/lib/beacon/template/heex/heex_decoder.ex +++ b/lib/beacon/template/heex/heex_decoder.ex @@ -126,6 +126,10 @@ defmodule Beacon.Template.HEEx.HEExDecoder do [name, "=", ?{, content, ?}] end + defp reconstruct_attr({name, _, _}) do + [name] + end + defp decode_eex_block(ast) do %{"type" => "eex_block", "content" => content, "children" => children} = Jason.decode!(ast) diff --git a/test/beacon/template/heex/heex_decoder_test.exs b/test/beacon/template/heex/heex_decoder_test.exs index 73feaad1b..060a45907 100644 --- a/test/beacon/template/heex/heex_decoder_test.exs +++ b/test/beacon/template/heex/heex_decoder_test.exs @@ -162,4 +162,11 @@ defmodule Beacon.Template.HEEx.HEExDecoderTest do test "live data assigns" do assert_equal(~S|<%= @name %>|, %{name: "Beacon"}) end + + test "script tag" do + assert_equal(~S""" + + """) + end end