Giter VIP home page Giter VIP logo

evalhook's People

Contributors

tario avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

lgo

evalhook's Issues

Evalhook 0.5.6, multiple line function definition no longer works.

I updated to the new gem version (with related dependencies) today.

The following code no longer works:

require "rubygems"
require "shikashi"

include Shikashi

module Sandboxer
  extend self
end

sandbox = Sandbox.new
priv = Privileges.new
priv.allow_method :puts

priv.instances_of(Sandboxer).allow_all

sandbox.run(priv, '
def go()
  puts "Printing a line!"
  puts "Printing a line!"
end', :base_namespace => Sandboxer)

Sandboxer.method("go").call()

The output only shows "Printing a line!" once (note that the go method makes 2 calls to puts.)

However, using the old dependencies,
"partialruby", '= 0.2.3'
"ruby_parser", '= 2.3.1'
"evalhook", '= 0.5.5'

The output shows:
Printing a line!
Printing a line!
as expected.

Methods shadowed by block variables

require "evalhook"
ctx = EvalHook::HookHandler.new
p ctx.evalhook("(1..10).map{|to_s| 'a'.to_s}")

Returns [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Expected: ["a", "a", "a", "a", "a", "a", "a", "a", "a", "a"]

Breaking lines before method calls does not work

While I was working around #5 , I used a chained invocation to get one logical line. The workaround was broken by the fix for #5.

The following generates a syntax error:

require "shikashi"

class X
  def foo
    print "X#foo\n"
    return self
  end

  def bar
    print "X#bar\n"
    return self
  end
end

include Shikashi

to_run = <<-END
# Following 3 lines should do the same thing twice
X.new.foo().bar()
X.new.foo()
.bar()
END

s = Sandbox.new
priv = Privileges.new
priv.allow_method :print
priv.allow_const_read("X") # allow the access of X constant
priv.object(X).allow(:new)
priv.instances_of(X).allow_all

puts "Running block: #{to_run}"
s.run(priv, to_run, :no_base_namespace => true)

This is a minor bug for me, but chaining calls is useful for a DSL.

Problems with method that more then one parameter

include Shikashi

privileges = Privileges.new        
privileges.allow_const_read "Kernel"
privileges.object(Kernel).allow_all
privileges.instances_of(Kernel).allow_all  

Sandbox.new.run(privileges, "Kernel.sprintf('%d', 123)")
I been having problems with ArgumentErrors when invoking methods with multiple arguments. They above gives me: ArgumentError: too few arguments

In a different scenario, I created they above for pure testing, im calling this method in class Chat

def self.send_property user_name, name, value

like this

Chat.send_property "a","b","c"

and I am seeing this

ArgumentError: wrong number of arguments (1 for 3)

but when I call it like this

Chat.send_property "a","b"

I am seeing

ArgumentError: wrong number of arguments (2 for 3)

If I call the methods outside of the Sandbox all is fine.

Does this ring a bell? I am using 'ruby-1.9.3-p194'

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

  spec.license = 'MIT'
  # or
  spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Memory leak in long running process

Copied from tario/shikashi#24:
"
Hello.

I am trying to eval code in shikashi sandbox in some long running process (single threaded). For each eval there is own sandbox + privileges objects. And according to ObjectSpace, none of these sandbox objects are cleared by garbage collector. There is also the same number of EvalhookHandler objects always exists.

Maybe I am just missed some kind of termination for sandbox?
"

Evaluated method only runs first line.

require "evalhook"

include EvalHook

to_run = <<-END
def puts_one_two_three()
  print "one two\\n"
  print "three\\n "
end
END

hh=HookHandler.new
hh.evalhook(to_run, binding)
puts_one_two_three

Expected: one two three
Got: one two

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.