Skip to content

Commit 6affea6

Browse files
committed
Prefix arguments in Mote.parse with underscore
The local variable in Mote.parse could potentially shadow the methods defined in the passed context. While this change does not prevent the shadowing, it makes it less likely to occur. Thanks to @srabuini for reporting this issue.
1 parent 94a97ff commit 6affea6

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/mote.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def self.src(template, vars = [])
4949
code << "__o; end"
5050
end
5151

52-
def self.parse(template, context = self, vars = [], name = "template")
53-
context.instance_eval(src(template, vars), name, -1)
52+
def self.parse(_template, _context = self, _vars = [], _name = "template")
53+
_context.instance_eval(src(_template, _vars), _name, -1)
5454
end
5555

5656
module Helpers

test/mote_test.rb

+8
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ def context.user; "Bruno"; end
9090
example = Mote.parse("{{ user }}", context)
9191
assert_equal "Bruno", example.call
9292
end
93+
94+
test "context with name" do
95+
context = Object.new
96+
def context.name; "Sebas"; end
97+
98+
example = Mote.parse("{{ self.name }}", context)
99+
assert_equal "Sebas", example.call
100+
end
93101

94102
test "locals" do
95103
example = Mote.parse("{{ user }}", TOPLEVEL_BINDING, [:user])

0 commit comments

Comments
 (0)