Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit e5a0ddc

Browse files
committed
Do not limit nesting depth of parsed JSON
I turned up some instances of files that killed the engine due to deeply nested JSON results from the parser: the JSON gem by default puts a limit on this.
1 parent 2974c08 commit e5a0ddc

File tree

8 files changed

+770
-8
lines changed

8 files changed

+770
-8
lines changed

‎lib/cc/engine/analyzers/analyzer_base.rb‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "cc/engine/analyzers/parser_error"
2+
require "cc/engine/analyzers/parser_base"
23

34
module CC
45
module Engine

‎lib/cc/engine/analyzers/javascript/parser.rb‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module CC
44
module Engine
55
module Analyzers
66
module Javascript
7-
class Parser
7+
class Parser < ParserBase
88
attr_reader :code, :filename, :syntax_tree
99

1010
def initialize(code, filename)
@@ -15,8 +15,7 @@ def initialize(code, filename)
1515
def parse
1616
runner = CommandLineRunner.new(js_command)
1717
runner.run(strip_shebang(code)) do |ast|
18-
json_ast = JSON.parse(ast)
19-
@syntax_tree = json_ast
18+
@syntax_tree = parse_json(ast)
2019
end
2120

2221
self
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module CC
2+
module Engine
3+
module Analyzers
4+
class ParserBase
5+
private
6+
7+
def parse_json(text)
8+
JSON.parse(text, max_nesting: false)
9+
end
10+
end
11+
end
12+
end
13+
end

‎lib/cc/engine/analyzers/php/parser.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module CC
66
module Engine
77
module Analyzers
88
module Php
9-
class Parser
9+
class Parser < ParserBase
1010
attr_reader :code, :filename, :syntax_tree
1111

1212
def initialize(code, filename)
@@ -17,7 +17,7 @@ def initialize(code, filename)
1717
def parse
1818
runner = CommandLineRunner.new("php #{parser_path}")
1919
runner.run(code) do |output|
20-
json = JSON.parse(output)
20+
json = parse_json(output)
2121

2222
@syntax_tree = CC::Engine::Analyzers::Php::Nodes::Node.new.tap do |node|
2323
node.stmts = CC::Engine::Analyzers::Php::AST.json_to_ast(json, filename)

‎lib/cc/engine/analyzers/python/parser.rb‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module CC
66
module Engine
77
module Analyzers
88
module Python
9-
class Parser
9+
class Parser < ParserBase
1010
attr_reader :code, :filename, :syntax_tree
1111

1212
def initialize(code, filename)
@@ -17,8 +17,7 @@ def initialize(code, filename)
1717
def parse
1818
runner = CommandLineRunner.new(python_command)
1919
runner.run(code) do |ast|
20-
json_ast = JSON.parse(ast)
21-
@syntax_tree = json_ast
20+
@syntax_tree = parse_json(ast)
2221
end
2322

2423
self

‎spec/cc/engine/analyzers/php/main_spec.rb‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@
4949
expect(json["fingerprint"]).to eq("667da0e2bab866aa2fe9d014a65d57d9")
5050
end
5151

52+
it "runs against complex files" do
53+
FileUtils.cp(fixture_path("symfony_configuration.php"), File.join(@code, "configuration.php"))
54+
result = run_engine(engine_conf).strip
55+
56+
expect(result).to match "\"type\":\"issue\""
57+
end
58+
5259
it "skips unparsable files" do
5360
create_source_file("foo.php", <<-EOPHP)
5461
<?php blorb &; "fee

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /