From 15e487601b523654fdd7fabd930526832011b565 Mon Sep 17 00:00:00 2001 From: Holden Oullette <6202965+houllette@users.noreply.github.com> Date: Wed, 13 Sep 2023 10:54:29 -0600 Subject: [PATCH 1/2] added normalization edge case for tuples --- lib/sobelow/parse.ex | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/sobelow/parse.ex b/lib/sobelow/parse.ex index d8ee966..3fca77d 100644 --- a/lib/sobelow/parse.ex +++ b/lib/sobelow/parse.ex @@ -236,10 +236,17 @@ defmodule Sobelow.Parse do {finding, List.flatten(opts)} end + # This handles normalizations for the case where the finding is a dot-access tuple + def normalize_finding({finding, {:., _, [{var, _, _}, field]}}) when is_atom(field) do + {finding, "#{atom_to_string(var)}.${atom_to_string(field)}"} + end + def normalize_finding({finding, opt}) do {finding, [opt]} end + defp atom_to_string(atom) when is_atom(atom), do: Atom.to_string(atom) + def get_erlang_funs_of_type(ast, type) do {_, acc} = Macro.prewalk(ast, [], &get_erlang_funs_of_type(&1, &2, type, :erlang)) acc From c3169ba05deb07ba2bdf8f899f4a9d2c54cbf722 Mon Sep 17 00:00:00 2001 From: dt <98478153+realcorvus@users.noreply.github.com> Date: Thu, 7 Dec 2023 14:04:14 -0500 Subject: [PATCH 2/2] Use trunc when idx is given as a float instead of an int --- lib/sobelow/parse.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sobelow/parse.ex b/lib/sobelow/parse.ex index d8ee966..8b074f1 100644 --- a/lib/sobelow/parse.ex +++ b/lib/sobelow/parse.ex @@ -455,7 +455,7 @@ defmodule Sobelow.Parse do end defp create_fun_cap(fun, meta, idx) when is_number(idx) do - opts = Enum.map(1..idx, fn i -> {:&, [], [i]} end) + opts = Enum.map(1..trunc(idx), fn i -> {:&, [], [i]} end) {fun, meta, opts} end