From f56fa2281942e85938a8c71852375933b1783d85 Mon Sep 17 00:00:00 2001 From: Pete Bevin Date: Sun, 25 Dec 2011 13:40:42 -0500 Subject: [PATCH 1/4] Fix crash when analyzing a = %Q{"} ConstantExtraction.constant_value was attempting to evaluate """, which threw a syntax error. Changed it to eval %Q{} or "" depending on what the code under analysis uses. --- lib/laser/analysis/sexp_extensions/constant_extraction.rb | 6 ++++-- .../sexp_extension_specs/constant_extraction_spec.rb | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/laser/analysis/sexp_extensions/constant_extraction.rb b/lib/laser/analysis/sexp_extensions/constant_extraction.rb index ded9249..13c62c3 100644 --- a/lib/laser/analysis/sexp_extensions/constant_extraction.rb +++ b/lib/laser/analysis/sexp_extensions/constant_extraction.rb @@ -45,9 +45,11 @@ def constant_value str = self[1] pos = self.parent.parent.source_begin first_two = lines[pos[0]-1][pos[1],2] - if first_two[0,1] == '"' || first_two == '%Q' + if first_two[0,1] == '"' eval(%Q{"#{str}"}) - else + elsif first_two == '%Q' + eval("%Q{#{str}}") + else str end when :string_content diff --git a/spec/analysis_specs/sexp_extension_specs/constant_extraction_spec.rb b/spec/analysis_specs/sexp_extension_specs/constant_extraction_spec.rb index d8769a3..ab28bd8 100644 --- a/spec/analysis_specs/sexp_extension_specs/constant_extraction_spec.rb +++ b/spec/analysis_specs/sexp_extension_specs/constant_extraction_spec.rb @@ -93,6 +93,14 @@ list[0][2].is_constant.should be true list[0][2].constant_value.should == 'abc \n \x12def' end + + it 'should not be fooled by quotes inside %Q{}' do + input = 'a = %Q{"}' + tree = annotate_all(input) + list = tree[1] + list[0][2].is_constant.should be true + list[0][2].constant_value.should == '"' + end end describe 'handling integer literals' do From adf507bfc58bac08ad7cad13907b11e541c8fd25 Mon Sep 17 00:00:00 2001 From: Pete Bevin Date: Mon, 26 Dec 2011 10:05:04 -0500 Subject: [PATCH 2/4] Fix stack overflow when requiring rexml/document The overflow happened while doing pre-order traversal of the root sexp - this switches out the recursive definition of Sexp#dfs for an iterative method using a stack. --- lib/laser/analysis/sexp.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/laser/analysis/sexp.rb b/lib/laser/analysis/sexp.rb index 5b5155d..cae33fa 100644 --- a/lib/laser/analysis/sexp.rb +++ b/lib/laser/analysis/sexp.rb @@ -98,14 +98,18 @@ def all_errors # Performs a DFS on the node, yielding each subnode (including the given node) # in DFS order. def dfs - yield self - self.children.each do |child| - next unless is_sexp?(child) - case child[0] - when Array - child.each { |x| x.dfs { |y| yield y}} - when ::Symbol - child.dfs { |y| yield y } + stack = [self] + while node = stack.pop + yield node + + node.children.reverse.each do |child| + next unless is_sexp?(child) + case child[0] + when Array + child.reverse.each { |x| stack.push(x) } + when ::Symbol + stack.push(child) + end end end end From 5645eea54af9f8fddaae496857faaa56d05fc93e Mon Sep 17 00:00:00 2001 From: Pete Bevin Date: Mon, 26 Dec 2011 10:59:41 -0500 Subject: [PATCH 3/4] Fix NoMethodError when --include is given --- lib/laser/runner.rb | 2 +- spec/runner_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/laser/runner.rb b/lib/laser/runner.rb index b93d924..05d2b0e 100644 --- a/lib/laser/runner.rb +++ b/lib/laser/runner.rb @@ -75,7 +75,7 @@ def get_settings opt :stdin, 'Read Ruby code from standard input', short: '-s' opt :'list-modules', 'Print the discovered, loaded modules' opt :profile, 'Run the profiler during execution' - opt :include, 'specify $LOAD_PATH directory (may be used more than once)', short: '-I', multi: true + opt :include, 'specify $LOAD_PATH directory (may be used more than once)', short: '-I', multi: true#, type: :string opt :S, 'look for scripts using PATH environment variable', short: '-S' warning_opts.each { |warning| opt(*warning) } end diff --git a/spec/runner_spec.rb b/spec/runner_spec.rb index 4a08c14..fd794ab 100644 --- a/spec/runner_spec.rb +++ b/spec/runner_spec.rb @@ -141,6 +141,12 @@ settings[:"report-fixed"].should be_true settings[:"report-fixed_given"].should be_true end + + it 'has a --include option' do + runner = Runner.new(['--include=/some/path', '-I', '/another/path']) + settings = runner.swizzling_argv { runner.get_settings } + settings[:include].should == ["/some/path", "/another/path"] + end end describe '#handle_global_options' do From 58581d52a4e8021ff7391337ca3f7a4faba1598e Mon Sep 17 00:00:00 2001 From: Pete Bevin Date: Mon, 26 Dec 2011 11:01:39 -0500 Subject: [PATCH 4/4] Fix error in previous commit --- lib/laser/runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/laser/runner.rb b/lib/laser/runner.rb index 05d2b0e..7aa127c 100644 --- a/lib/laser/runner.rb +++ b/lib/laser/runner.rb @@ -75,7 +75,7 @@ def get_settings opt :stdin, 'Read Ruby code from standard input', short: '-s' opt :'list-modules', 'Print the discovered, loaded modules' opt :profile, 'Run the profiler during execution' - opt :include, 'specify $LOAD_PATH directory (may be used more than once)', short: '-I', multi: true#, type: :string + opt :include, 'specify $LOAD_PATH directory (may be used more than once)', short: '-I', multi: true, type: :string opt :S, 'look for scripts using PATH environment variable', short: '-S' warning_opts.each { |warning| opt(*warning) } end