我想讓clj-sandbox允許def
和defn
。Clj-Sandbox的bug?
我沒有得到def
工作任何麻煩:
(use 'net.licenser.sandbox
'net.licenser.sandbox.tester
'net.licenser.sandbox.matcher)
(def my-tester
(extend-tester secure-tester (whitelist (function-matcher 'def))))
(def my-sandbox
(stringify-sandbox (new-sandbox :tester my-tester)))
(my-sandbox
"(def a (clojure.core/fn a ([b] (inc b))))")
(println (my-sandbox "(a 5)"))
然而,defn
是給我的問題。它看起來像我的代碼將沙箱準則,但後來在執行過程中失敗:
; (macroexpand '(defn y [z] (inc z)))
(my-sandbox
"(def y (.withMeta (clojure.core/fn y ([z] (inc z))) (.meta (var y))))")
; java.lang.SecurityException: Exception in sandboxed code.
這是一個錯誤,還是我做錯了什麼?