From 62412288a6090b454560d697385d1f9296455db6 Mon Sep 17 00:00:00 2001 From: Mike Blaguszewski Date: Tue, 20 Aug 2024 13:46:33 -0400 Subject: [PATCH 1/2] Issue #168: trailing content on a sobelow_ignore line silently breaks parsing --- lib/sobelow.ex | 4 ++++ lib/sobelow/parse.ex | 2 +- test/parser_test.exs | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/sobelow.ex b/lib/sobelow.ex index e786056..1dfb966 100644 --- a/lib/sobelow.ex +++ b/lib/sobelow.ex @@ -291,6 +291,10 @@ defmodule Sobelow do Application.get_env(:sobelow, key) end + def put_env(key, value) do + Application.put_env(:sobelow, key, value) + end + defp print_banner do """ ############################################## diff --git a/lib/sobelow/parse.ex b/lib/sobelow/parse.ex index 27d1d26..cedb325 100644 --- a/lib/sobelow/parse.ex +++ b/lib/sobelow/parse.ex @@ -58,7 +58,7 @@ defmodule Sobelow.Parse do if Sobelow.get_env(:skip) do String.replace( content, - ~r/#\s?sobelow_skip (\[(\"[^"]+\"(,|, )?)+\])/, + ~r/#\s?sobelow_skip (\[(\"[^"]+?\"(,|, )?)+?\]).*/, "@sobelow_skip \\g{1}" ) else diff --git a/test/parser_test.exs b/test/parser_test.exs index 0a41551..862a5fc 100644 --- a/test/parser_test.exs +++ b/test/parser_test.exs @@ -2,6 +2,7 @@ defmodule SobelowTest.ParserTest do use ExUnit.Case import ExUnit.CaptureIO alias Sobelow.RCE.CodeModule + alias Sobelow.Parse @metafile %{filename: "test.ex", controller?: true} @@ -27,4 +28,15 @@ defmodule SobelowTest.ParserTest do assert capture_io(run_test) =~ "Code Execution in `Code.eval_string` - Medium Confidence" end + + test "Remainder of line after sobelow_skip expression is ignored" do + Sobelow.put_env(:skip, true) + file = "./test/fixtures/parser/parse_skip.ex" + + %{def_funs: defs} = Parse.ast(file) + |> Parse.get_meta_funs() + assert not Enum.empty?(defs) + after + Sobelow.put_env(:skip, false) + end end From c9eed6b49fdfad23de9087fa5ab977c2aa9273ae Mon Sep 17 00:00:00 2001 From: Mike Blaguszewski Date: Tue, 20 Aug 2024 16:05:37 -0400 Subject: [PATCH 2/2] Test fixture --- test/fixtures/parser/parse_skip.ex | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 test/fixtures/parser/parse_skip.ex diff --git a/test/fixtures/parser/parse_skip.ex b/test/fixtures/parser/parse_skip.ex new file mode 100644 index 0000000..5d2fd73 --- /dev/null +++ b/test/fixtures/parser/parse_skip.ex @@ -0,0 +1,8 @@ +defmodule Mod do + @moduledoc false + + # sobelow_skip ["Foo"] (no foo violations here) + def func() do + :ok + end +end