Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reentrancy (invoking erubis from template) currupts the output of the outer invocation #9

Open
bughit opened this issue Dec 8, 2016 · 2 comments

Comments

@bughit
Copy link

bughit commented Dec 8, 2016

require 'erubis'
require 'erb'

def inner_erubis
  Erubis::Eruby.new('inner_template <%= "ruby_output" %> inner_template').result
  'ruby_output'
end


def inner_erb
  Erubis::Eruby.new('inner_template <%= "ruby_output" %> inner_template').result
  'ruby_output'
end

puts ERB.new('outer_template <%= inner_erb %> outer_template').result # outer_template ruby_output outer_template
puts Erubis::Eruby.new('outer_template <%= inner_erubis %> outer_template').result # inner_template ruby_output inner_template outer_template
@bughit bughit changed the title rentrancy (invoking erubis from template) currupts output reentrancy (invoking erubis from template) currupts output Dec 8, 2016
@bughit bughit changed the title reentrancy (invoking erubis from template) currupts output reentrancy (invoking erubis from template) currupts the output of the outer invocation Dec 8, 2016
@bughit
Copy link
Author

bughit commented Dec 8, 2016

updated example to better illustrate the problem

@bughit
Copy link
Author

bughit commented Dec 9, 2016

the default binding value should be TOPLEVEL_BINDING.dup

    def result(_binding_or_hash=TOPLEVEL_BINDING)
      _arg = _binding_or_hash
      if _arg.is_a?(Hash)
        _b = binding()
        eval _arg.collect{|k,v| "#{k} = _arg[#{k.inspect}]; "}.join, _b
      elsif _arg.is_a?(Binding)
        _b = _arg
      elsif _arg.nil?
        _b = binding()
      else
        raise ArgumentError.new("#{self.class.name}#result(): argument should be Binding or Hash but passed #{_arg.class.name} object.")
      end
      return eval(@src, _b, (@filename || '(erubis'))
    end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant