Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
Brakeman
提交
998bb0da
B
Brakeman
项目概览
李少辉-开发者
/
Brakeman
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
Brakeman
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
998bb0da
编写于
5月 29, 2014
作者:
J
Justin Collins
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ignore branches when assigning via +=
上级
43f92bf4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
67 addition
and
3 deletion
+67
-3
lib/brakeman/processors/alias_processor.rb
lib/brakeman/processors/alias_processor.rb
+25
-2
test/tests/alias_processor.rb
test/tests/alias_processor.rb
+42
-1
未找到文件。
lib/brakeman/processors/alias_processor.rb
浏览文件 @
998bb0da
...
...
@@ -257,12 +257,18 @@ class Brakeman::AliasProcessor < Brakeman::SexpProcessor
#Local assignment
# x = 1
def
process_lasgn
exp
self_assign
=
self_assign?
(
exp
.
lhs
,
exp
.
rhs
)
exp
.
rhs
=
process
exp
.
rhs
if
sexp?
exp
.
rhs
return
exp
if
exp
.
rhs
.
nil?
local
=
Sexp
.
new
(
:lvar
,
exp
.
lhs
).
line
(
exp
.
line
||
-
2
)
set_value
local
,
exp
.
rhs
if
self_assign
# Skip branching
env
[
local
]
=
exp
.
rhs
else
set_value
local
,
exp
.
rhs
end
exp
end
...
...
@@ -270,10 +276,19 @@ class Brakeman::AliasProcessor < Brakeman::SexpProcessor
#Instance variable assignment
# @x = 1
def
process_iasgn
exp
self_assign
=
self_assign?
(
exp
.
lhs
,
exp
.
rhs
)
exp
.
rhs
=
process
exp
.
rhs
ivar
=
Sexp
.
new
(
:ivar
,
exp
.
lhs
).
line
(
exp
.
line
)
set_value
ivar
,
exp
.
rhs
if
self_assign
if
env
[
ivar
].
nil?
and
@meth_env
@meth_env
[
ivar
]
=
exp
.
rhs
else
env
[
ivar
]
=
exp
.
rhs
end
else
set_value
ivar
,
exp
.
rhs
end
exp
end
...
...
@@ -727,6 +742,14 @@ class Brakeman::AliasProcessor < Brakeman::SexpProcessor
end
end
#Return true if for x += blah or @x += blah
def
self_assign?
var
,
value
call?
value
and
value
.
method
==
:
+
and
node_type?
value
.
target
,
:lvar
,
:ivar
and
value
.
target
.
value
==
var
end
def
value_from_if
exp
if
block?
exp
.
else_clause
or
block?
exp
.
then_clause
#If either clause is more than a single expression, just use entire
...
...
test/tests/alias_processor.rb
浏览文件 @
998bb0da
...
...
@@ -255,7 +255,7 @@ class AliasProcessorTests < Test::Unit::TestCase
end
def
test_simple_or_operation_compaction
assert_alias
"[0,
((1 || 2) || 3)
, (4 || 8)]"
,
<<-
RUBY
assert_alias
"[0,
4
, (4 || 8)]"
,
<<-
RUBY
x = 1
if z
...
...
@@ -546,4 +546,45 @@ class AliasProcessorTests < Test::Unit::TestCase
end
OUTPUT
end
def
test_no_branch_for_plus_equals_with_string
assert_alias
'"abc"'
,
<<-
INPUT
x = "a"
x += "b" if something
x += "c" if something_else
x
INPUT
end
def
test_no_branch_for_plus_equals_with_string_in_ivar
assert_alias
'"abc"'
,
<<-
INPUT
@x = "a"
@x += "b" if something
@x += "c" if something_else
@x
INPUT
end
#We could do better, but this prevents some Sexp explosions and retains
#information about the values
def
test_no_branch_for_plus_equals_with_interpolated_string
assert_alias
'"a" + "#{b}" + "c"'
,
<<-
'INPUT'
x = "a"
x += "
#{
b
}
" if something
x += "c" if something_else
x
INPUT
end
#Unfortunate to go to this behavior which loses information
#but I can't think of a scenario in which the several integers
#in ORs would be handled right anyway
def
test_no_branch_for_plus_equals_with_number
assert_alias
'6'
,
<<-
INPUT
x = 1
x += 2 if something
x += 3 if something_else
x
INPUT
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录