From 9caae856c4a89c61e1cf1272fce48faf87dafb84 Mon Sep 17 00:00:00 2001 From: "L.J. Hill" <foehawk@gmail.com> Date: Wed, 21 Sep 2016 14:10:35 -0400 Subject: [PATCH] Test generator: scrub strings after comments This fixes #220. Removing strings from test files is still dangerous, but much less likely to cause problems after this change to do the removal after removing comments. The bug could still manifest if a test file contains defines two macros, one that contains a single quotation mark and then another defined somewhere after it that contains a single quotation mark. Everything in between the aforementioned quotation marks would still be ignored after this commit, but that is an unlikely scenario. --- auto/generate_test_runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index e4f13c7..1745f16 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -95,9 +95,9 @@ class UnityTestRunnerGenerator tests_and_line_numbers = [] source_scrubbed = source.clone - source_scrubbed = source_scrubbed.gsub(/"[^"]*"/, '') # remove things in strings source_scrubbed = source_scrubbed.gsub(/\/\/.*$/, '') # remove line comments source_scrubbed = source_scrubbed.gsub(/\/\*.*?\*\//m, '') # remove block comments + source_scrubbed = source_scrubbed.gsub(/"[^"]*"/, '') # remove things in strings lines = source_scrubbed.split(/(^\s*\#.*$) # Treat preprocessor directives as a logical line | (;|\{|\}) /x) # Match ;, {, and } as end of lines