Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
Brakeman
提交
36cdce51
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 搜索 >>
提交
36cdce51
编写于
11月 24, 2014
作者:
J
Justin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #577 from presidentbeef/handle_multiple_assignment
Handle multiple assignment
上级
6261a5c6
f9011adc
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
67 addition
and
6 deletion
+67
-6
lib/brakeman/processors/alias_processor.rb
lib/brakeman/processors/alias_processor.rb
+27
-0
lib/ruby_parser/bm_sexp.rb
lib/ruby_parser/bm_sexp.rb
+17
-5
test/tests/alias_processor.rb
test/tests/alias_processor.rb
+12
-0
test/tests/sexp.rb
test/tests/sexp.rb
+11
-1
未找到文件。
lib/brakeman/processors/alias_processor.rb
浏览文件 @
36cdce51
...
...
@@ -351,6 +351,33 @@ class Brakeman::AliasProcessor < Brakeman::SexpProcessor
exp
end
# Multiple/parallel assignment:
#
# x, y = z, w
def
process_masgn
exp
unless
array?
exp
[
1
]
and
array?
exp
[
2
]
and
exp
[
1
].
length
==
exp
[
2
].
length
return
process_default
(
exp
)
end
vars
=
exp
[
1
].
dup
vals
=
exp
[
2
].
dup
vars
.
shift
vals
.
shift
# Call each assignment as if it is normal
vars
.
each_with_index
do
|
var
,
i
|
val
=
vals
[
i
]
if
val
assign
=
var
.
dup
assign
.
rhs
=
val
process
assign
end
end
exp
end
#Merge values into hash when processing
#
# h.merge! :something => "value"
...
...
lib/ruby_parser/bm_sexp.rb
浏览文件 @
36cdce51
...
...
@@ -4,7 +4,7 @@
class
Sexp
attr_reader
:paren
attr_accessor
:original_line
,
:or_depth
ASSIGNMENT_BOOL
=
[
:gasgn
,
:iasgn
,
:lasgn
,
:cvdecl
,
:cdecl
,
:or
,
:and
,
:colon2
]
ASSIGNMENT_BOOL
=
[
:gasgn
,
:iasgn
,
:lasgn
,
:cvdecl
,
:c
vasgn
,
:c
decl
,
:or
,
:and
,
:colon2
]
def
method_missing
name
,
*
args
#Brakeman does not use this functionality,
...
...
@@ -419,6 +419,7 @@ class Sexp
#Sets the left hand side of assignment or boolean.
def
lhs
=
exp
expect
*
ASSIGNMENT_BOOL
@my_hash_value
=
nil
self
[
1
]
=
exp
end
...
...
@@ -427,14 +428,25 @@ class Sexp
# s(:lasgn, :x, s(:lit, 1))
# ^--rhs---^
def
rhs
expect
*
ASSIGNMENT_BOOL
self
[
2
]
expect
:attrasgn
,
*
ASSIGNMENT_BOOL
if
self
.
node_type
==
:attrasgn
self
[
3
]
else
self
[
2
]
end
end
#Sets the right hand side of assignment or boolean.
def
rhs
=
exp
expect
*
ASSIGNMENT_BOOL
self
[
2
]
=
exp
expect
:attrasgn
,
*
ASSIGNMENT_BOOL
@my_hash_value
=
nil
if
self
.
node_type
==
:attrasgn
self
[
3
]
=
exp
else
self
[
2
]
=
exp
end
end
#Returns name of method being defined in a method definition.
...
...
test/tests/alias_processor.rb
浏览文件 @
36cdce51
...
...
@@ -600,6 +600,18 @@ class AliasProcessorTests < Test::Unit::TestCase
OUTPUT
end
def
test_multiple_assignment
assert_output
<<-
INPUT
,
<<-
OUTPUT
x, $y = 1, 2
x
$y
INPUT
x, $y = 1, 2
1
2
OUTPUT
end
def
test_branch_with_self_assign_target
assert_alias
'a.w.y'
,
<<-
INPUT
x = a
...
...
test/tests/sexp.rb
浏览文件 @
36cdce51
...
...
@@ -162,13 +162,23 @@ class SexpTests < Test::Unit::TestCase
assert_equal
s
(
:lit
,
1
),
exp
.
rhs
end
def
test_class_variable_
assignment
def
test_class_variable_
declaration
exp
=
parse
'@@x = 1'
assert_equal
:cvdecl
,
exp
.
node_type
assert_equal
:@@x
,
exp
.
lhs
assert_equal
s
(
:lit
,
1
),
exp
.
rhs
end
def
test_class_variable_assignment
exp
=
parse
'def x; @@a = 1; end'
asgn
=
exp
.
last
assert_equal
:cvasgn
,
asgn
.
node_type
assert_equal
:@@a
,
asgn
.
lhs
assert_equal
s
(
:lit
,
1
),
asgn
.
rhs
end
def
test_method_def_name
exp
=
parse
<<-
RUBY
def x(y)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录