muzang-plugins 1.1.5 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,20 +1,18 @@
|
|
1
1
|
module Muzang
|
2
2
|
module Plugins
|
3
|
-
|
4
|
-
class << Safe
|
3
|
+
class Safe
|
5
4
|
def safe(code, sandbox=nil)
|
6
5
|
error = nil
|
7
6
|
|
8
7
|
begin
|
9
8
|
$-w = nil
|
10
|
-
sandbox ||= Object.new
|
11
|
-
yield(sandbox) if block_given?
|
9
|
+
@sandbox ||= Object.new
|
10
|
+
yield(@sandbox) if block_given?
|
12
11
|
|
13
|
-
$SAFE =
|
14
|
-
|
15
|
-
result = Marshal.load(Marshal.dump(value))
|
12
|
+
$SAFE = 3
|
13
|
+
result = eval(code, @sandbox.send(:binding))
|
16
14
|
rescue Exception => error
|
17
|
-
error =
|
15
|
+
error = error
|
18
16
|
end
|
19
17
|
|
20
18
|
return result, error
|
@@ -46,7 +44,8 @@ module Muzang
|
|
46
44
|
|
47
45
|
def safe(*args, &block)
|
48
46
|
unless args.first =~ /EM|EventMachine/
|
49
|
-
|
47
|
+
@safe ||= Safe.new
|
48
|
+
@safe.safe(*args, &block)
|
50
49
|
end
|
51
50
|
end
|
52
51
|
end
|
data/spec/muzang-eval_spec.rb
CHANGED
@@ -41,5 +41,22 @@ module Muzang::Plugins
|
|
41
41
|
eventually(true) { @connection.messages.include? "Error: Exception" }
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
it "should keep state" do
|
46
|
+
@message.message = '% @state = {:true => true}'
|
47
|
+
EM.run do
|
48
|
+
@message_state = @message.dup
|
49
|
+
@message_state.message = '% "super #{@state}"'
|
50
|
+
@eval.call(@connection, @message)
|
51
|
+
EM.add_timer(0.5) do
|
52
|
+
@eval.call(@connection, @message_state)
|
53
|
+
end
|
54
|
+
|
55
|
+
eventually(true) do
|
56
|
+
@connection.messages.include?("{:true=>true}") &&
|
57
|
+
@connection.messages.include?("super {:true=>true}")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
44
61
|
end
|
45
62
|
end
|