lib/delorean/base.rb in delorean_lang-0.3.1 vs lib/delorean/base.rb in delorean_lang-0.3.2

- old
+ new

@@ -67,27 +67,33 @@ module BaseModule class NodeCall < Struct.new(:_e, :engine, :node, :params) def evaluate(attr) # FIXME: evaluate() modifies params! => need to clone it. - # This is pretty awful. + # This is pretty awful. NOTE: can't sanitize params as Marty + # patches NodeCall and modifies params to send _parent_id. + # This whole thing needs to be redone. engine.evaluate(node, attr, params.clone) end def %(args) raise "bad arg to %" unless args.is_a?(Array) # FIXME: params.clone!!!! - engine.evaluate_attrs_hash(node, args, params.clone) + engine.eval_to_hash(node, args, params.clone) end # add new arguments, results in a new NodeCall def +(args) raise "bad arg to %" unless args.is_a?(Hash) NodeCall.new(_e, engine, node, params.merge(args)) end + + def sanitized_params + BaseClass._sanitize_hash(params) + end end class BaseClass def self._get_attr(obj, attr, _e) # FIXME: even Javascript which is superpermissive raises an @@ -140,9 +146,18 @@ raise InvalidIndex unless args[0].is_a?(Fixnum) && (!args[1] || args[1].is_a?(Fixnum)) obj[*args] else raise InvalidIndex + end + end + + ###################################################################### + + def self._sanitize_hash(_e) + _e.each_with_object({}) do + |(k,v), h| + h[k] = v if k =~ /\A[a-z][A-Za-z0-9_]*\z/ end end ######################################################################