diff --git a/lib/data_layer/data_layer.ex b/lib/data_layer/data_layer.ex index 838cca6..a2816cd 100644 --- a/lib/data_layer/data_layer.ex +++ b/lib/data_layer/data_layer.ex @@ -333,7 +333,7 @@ defmodule AshBlog.DataLayer do resource |> Ash.Resource.Info.attributes() |> Map.new(fn attr -> - {attr.name, Map.get(result, to_string(attr.name))} + {attr.name, decode_formatting_hacks(Map.get(result, to_string(attr.name)))} end) |> Map.put(AshBlog.DataLayer.Info.body_attribute(resource), body) @@ -375,6 +375,19 @@ defmodule AshBlog.DataLayer do end end + defp decode_formatting_hacks(value) when is_list(value) do + Enum.map(value, &decode_formatting_hacks/1) + end + + defp decode_formatting_hacks(value) when is_binary(value) do + # I hate this more than words can describe + value + |> String.replace("__ash_blog_single_quote_hack__", ",") + |> String.replace("__ash_blog_newline_hack__", "\n") + end + + defp decode_formatting_hacks(value), do: value + @doc false def cast_record(record, resource) do resource @@ -543,7 +556,8 @@ defmodule AshBlog.DataLayer do defp escape_string(value) do value |> to_string() - |> String.replace("'", "\\'") + |> String.replace("'", "__ash_blog_single_quote_hack__") + |> String.replace("\n", "__ash_blog_newline_hack__") end case Code.ensure_compiled(Mix) do