mirror of
https://github.com/ash-project/ash_blog.git
synced 2024-09-19 12:53:45 +12:00
fix: horrendous hacks to account for whitespace and single quotes in strings
This commit is contained in:
parent
7ccc812e69
commit
5d185eccd1
1 changed files with 16 additions and 2 deletions
|
@ -333,7 +333,7 @@ defmodule AshBlog.DataLayer do
|
||||||
resource
|
resource
|
||||||
|> Ash.Resource.Info.attributes()
|
|> Ash.Resource.Info.attributes()
|
||||||
|> Map.new(fn attr ->
|
|> 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)
|
end)
|
||||||
|> Map.put(AshBlog.DataLayer.Info.body_attribute(resource), body)
|
|> Map.put(AshBlog.DataLayer.Info.body_attribute(resource), body)
|
||||||
|
|
||||||
|
@ -375,6 +375,19 @@ defmodule AshBlog.DataLayer do
|
||||||
end
|
end
|
||||||
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
|
@doc false
|
||||||
def cast_record(record, resource) do
|
def cast_record(record, resource) do
|
||||||
resource
|
resource
|
||||||
|
@ -543,7 +556,8 @@ defmodule AshBlog.DataLayer do
|
||||||
defp escape_string(value) do
|
defp escape_string(value) do
|
||||||
value
|
value
|
||||||
|> to_string()
|
|> to_string()
|
||||||
|> String.replace("'", "\\'")
|
|> String.replace("'", "__ash_blog_single_quote_hack__")
|
||||||
|
|> String.replace("\n", "__ash_blog_newline_hack__")
|
||||||
end
|
end
|
||||||
|
|
||||||
case Code.ensure_compiled(Mix) do
|
case Code.ensure_compiled(Mix) do
|
||||||
|
|
Loading…
Reference in a new issue