rufus-treechecker 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.txt +5 -0
- data/lib/rufus/treechecker.rb +22 -10
- data/spec/high_spec.rb +10 -0
- metadata +25 -2
data/CHANGELOG.txt
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
= rufus-treechecker CHANGELOG.txt
|
3
3
|
|
4
4
|
|
5
|
+
== rufus-treechecker - 1.0.7 released 2011/07/31
|
6
|
+
|
7
|
+
- "rescue => e" not triggering "global vars forbidden" anymore
|
8
|
+
|
9
|
+
|
5
10
|
== rufus-treechecker - 1.0.6 released 2011/05/10
|
6
11
|
|
7
12
|
- clone then add_rules issue, the real fix
|
data/lib/rufus/treechecker.rb
CHANGED
@@ -122,7 +122,7 @@ module Rufus
|
|
122
122
|
#
|
123
123
|
class TreeChecker
|
124
124
|
|
125
|
-
VERSION = '1.0.
|
125
|
+
VERSION = '1.0.7'
|
126
126
|
|
127
127
|
# pretty-prints the sexp tree of the given rubycode
|
128
128
|
#
|
@@ -242,16 +242,17 @@ module Rufus
|
|
242
242
|
# accepted patterns are evaluated before excluded patterns
|
243
243
|
# if one is found the excluded patterns are skipped
|
244
244
|
|
245
|
-
pats = @accepted_patterns[sexp.first]
|
246
|
-
pats.
|
245
|
+
pats = @accepted_patterns[sexp.first] || []
|
246
|
+
return false if pats.find { |pat| check_pattern(sexp, pat) }
|
247
247
|
|
248
|
-
pats = @excluded_patterns[sexp.first]
|
249
|
-
return unless pats
|
248
|
+
pats = @excluded_patterns[sexp.first] || []
|
250
249
|
|
251
250
|
pats.each do |pat, msg|
|
252
251
|
raise SecurityError.new(msg) if check_pattern(sexp, pat)
|
253
252
|
end
|
254
253
|
end
|
254
|
+
|
255
|
+
true
|
255
256
|
end
|
256
257
|
|
257
258
|
def freeze
|
@@ -303,11 +304,14 @@ module Rufus
|
|
303
304
|
|
304
305
|
return false if sexp.length < pat.length
|
305
306
|
|
306
|
-
(1..pat.length-1).each do |i|
|
307
|
+
(1..pat.length - 1).each do |i|
|
308
|
+
#puts '.'
|
309
|
+
#p (pat[i], sexp[i])
|
310
|
+
#p (pat[i] != :any and pat[i] != sexp[i])
|
307
311
|
return false if (pat[i] != :any and pat[i] != sexp[i])
|
308
312
|
end
|
309
313
|
|
310
|
-
|
314
|
+
true # we have a match
|
311
315
|
end
|
312
316
|
end
|
313
317
|
|
@@ -432,7 +436,7 @@ module Rufus
|
|
432
436
|
@current_set.exclude_symbol(:defn, 'method definitions are forbidden')
|
433
437
|
end
|
434
438
|
|
435
|
-
# Bans the
|
439
|
+
# Bans the definition and the [re]opening of classes
|
436
440
|
#
|
437
441
|
# a list of exceptions (classes) can be passed. Subclassing those
|
438
442
|
# exceptions is permitted.
|
@@ -466,6 +470,9 @@ module Rufus
|
|
466
470
|
#
|
467
471
|
def exclude_global_vars
|
468
472
|
|
473
|
+
@current_set.accept_pattern([ :gvar, :$! ])
|
474
|
+
# "rescue => e" is accepted
|
475
|
+
|
469
476
|
@current_set.exclude_symbol(:gvar, 'global vars are forbidden')
|
470
477
|
@current_set.exclude_symbol(:gasgn, 'global vars are forbidden')
|
471
478
|
end
|
@@ -516,10 +523,15 @@ module Rufus
|
|
516
523
|
#
|
517
524
|
def do_check(sexp)
|
518
525
|
|
519
|
-
@set.check(sexp)
|
526
|
+
continue = @set.check(sexp)
|
520
527
|
|
521
|
-
return unless
|
528
|
+
return unless continue
|
529
|
+
# found an accepted pattern, no need to dive into it
|
522
530
|
|
531
|
+
return unless sexp.is_a?(Array)
|
532
|
+
# check over, seems fine...
|
533
|
+
|
534
|
+
#
|
523
535
|
# check children
|
524
536
|
|
525
537
|
sexp.each { |c| do_check(c) }
|
data/spec/high_spec.rb
CHANGED
@@ -19,9 +19,19 @@ describe Rufus::TreeChecker do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'does not block "1 + 1"' do
|
22
|
+
|
22
23
|
lambda { tc.check("1 + 1") }.should_not raise_error
|
23
24
|
end
|
24
25
|
|
26
|
+
it 'does not block begin/rescue/end' do
|
27
|
+
|
28
|
+
tc.check(%{
|
29
|
+
begin
|
30
|
+
rescue => e
|
31
|
+
end
|
32
|
+
})
|
33
|
+
end
|
34
|
+
|
25
35
|
[
|
26
36
|
|
27
37
|
"$ENV",
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rufus-treechecker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 7
|
10
|
+
version: 1.0.7
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- John Mettraux
|
@@ -10,7 +15,7 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2011-
|
18
|
+
date: 2011-07-31 00:00:00 +09:00
|
14
19
|
default_executable:
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
@@ -21,6 +26,11 @@ dependencies:
|
|
21
26
|
requirements:
|
22
27
|
- - ">="
|
23
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 5
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 0
|
33
|
+
- 5
|
24
34
|
version: 2.0.5
|
25
35
|
type: :runtime
|
26
36
|
version_requirements: *id001
|
@@ -32,6 +42,9 @@ dependencies:
|
|
32
42
|
requirements:
|
33
43
|
- - ">="
|
34
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
35
48
|
version: "0"
|
36
49
|
type: :development
|
37
50
|
version_requirements: *id002
|
@@ -43,6 +56,10 @@ dependencies:
|
|
43
56
|
requirements:
|
44
57
|
- - ">="
|
45
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 2
|
62
|
+
- 0
|
46
63
|
version: "2.0"
|
47
64
|
type: :development
|
48
65
|
version_requirements: *id003
|
@@ -86,12 +103,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
103
|
requirements:
|
87
104
|
- - ">="
|
88
105
|
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
89
109
|
version: "0"
|
90
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
111
|
none: false
|
92
112
|
requirements:
|
93
113
|
- - ">="
|
94
114
|
- !ruby/object:Gem::Version
|
115
|
+
hash: 3
|
116
|
+
segments:
|
117
|
+
- 0
|
95
118
|
version: "0"
|
96
119
|
requirements: []
|
97
120
|
|