Shopify/liquid — pull request #94 by ppgengler (2012-02-10 20:18:48+00:00)
Title: Context handles false value in an environment incorrectly

I've added tests to test/liquid/context_test.rb and test/liquid/variable_test.rb that demonstrate the issue, but basically if you have "foo" that gets set as part of the environments on initialization of a Context, which is how Template.render passes a Hash in, then the context returns the wrong value:

```
context = Context.new([{"foo" => false}, {}]))
assert_equal false, context["foo"] # expected: false, got: nil
```

What does work, and what is tested currently, is using a scope of the Context:

```
context = Context.new
context["foo"] = false
assert_equal false, context["foo"] # This works
```

The issue, as corrected in the commit to lib/liquid/context.rb is to check

```
unless (variable = lookup_and_evaluate(e, key)).nil?
```

for returning nil specifically, which will break on true or false correctly, instead of checking

```
if variable = lookup_and_evaluate(e, key)
```

which only breaks the search on true and not false.

In the normal way of things I need this soon, so I've updated the test to check both of these setter methods in the test_variables test and it does indeed fail only with false in the environments case and then went and fixed that. And in the name of giving back to the community, I am submitting this pull request to either get included, or improved upon as applicable. However, I didn't scour the rest of the tests to see if they should also test both cases, but I figured doing one as an example would help someone with a better understanding of the library decide where to apply it.

Thanks,
\Peter