safe_ruby 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/safe_ruby.rb +1 -1
- data/lib/safe_ruby_runner.rb +12 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 425c072f463f6327df204384704f8ae03a7492dd
|
4
|
+
data.tar.gz: 8fdd2f48678c45f09a9525e689dce7c7f2466ba4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a55b54043be58f25ecbe306885f732895a4c98816a6e4df9f379f26d7cb14249d2b7b79dc3f3fc44624ba6b70ad75e5fbd00cf8a4a97fbc8923982fdc1535fc6
|
7
|
+
data.tar.gz: c0e3ccf2fe3fc326ea06f3d9a5ca1ff255236e92a9a1f29244ccbae25dcb9aba602133116df105bd65d46f467fb403a324deede1df3419a85a5e0d7d1a902f2c
|
data/lib/safe_ruby.rb
CHANGED
data/lib/safe_ruby_runner.rb
CHANGED
@@ -3,12 +3,15 @@ class EvalError < StandardError
|
|
3
3
|
end
|
4
4
|
|
5
5
|
class SafeRuby
|
6
|
-
DEFAULTS = { timeout: 5
|
6
|
+
DEFAULTS = { timeout: 5,
|
7
|
+
raise_errors: true }
|
7
8
|
|
8
9
|
def initialize(code, options={})
|
9
|
-
@code = code
|
10
10
|
options = DEFAULTS.merge(options)
|
11
|
-
|
11
|
+
|
12
|
+
@code = code
|
13
|
+
@raise_errors = options[:raise_errors]
|
14
|
+
@timeout = options[:timeout]
|
12
15
|
end
|
13
16
|
|
14
17
|
def self.eval(code, options={})
|
@@ -36,7 +39,11 @@ class SafeRuby
|
|
36
39
|
begin
|
37
40
|
Marshal.load(data)
|
38
41
|
rescue => e
|
39
|
-
|
42
|
+
if @raise_errors
|
43
|
+
raise data
|
44
|
+
else
|
45
|
+
return data
|
46
|
+
end
|
40
47
|
end
|
41
48
|
end
|
42
49
|
|
@@ -52,7 +59,7 @@ class SafeRuby
|
|
52
59
|
file = Tempfile.new('saferuby')
|
53
60
|
file.write(MAKE_SAFE_CODE)
|
54
61
|
file.write <<-STRING
|
55
|
-
result = eval(
|
62
|
+
result = eval(%q(#{@code}))
|
56
63
|
print Marshal.dump(result)
|
57
64
|
STRING
|
58
65
|
file.rewind
|