Skip to content

Commit

Permalink
[liquid] default filter should not override false values
Browse files Browse the repository at this point in the history
  • Loading branch information
mikz committed Feb 1, 2019
1 parent 2edf4e6 commit d1b258d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed

- Improve startup time by improving templating performance and caching filesystem access [PR #964](https://github.com/3scale/apicast/pull/964)
- Liquid `default` filter now does not override `false` values [PR #964](https://github.com/3scale/apicast/pull/964)

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion gateway/Roverfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ busted 2.0.rc12-1||testing
dkjson 2.5-2||testing
inspect 3.1.1-0||production
ldoc 1.4.6-2||development
liquid 0.1.0-1||production
liquid 0.1.3-1||production
ljsonschema 0.1.0-1||testing
lua-resty-env 0.4.0-1||production
lua-resty-execvp 0.1.1-1||production
Expand Down
2 changes: 1 addition & 1 deletion gateway/src/apicast/cli/template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function _M:interpret(str)
end)

filter_set:add_filter('default', function(value, default)
return value or default
if value == nil then return default else return value end
end)

filter_set:add_filter('starts_with', function(string, ...)
Expand Down
19 changes: 19 additions & 0 deletions spec/cli/template_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
local _M = require('apicast.cli.template')

describe('Liquid Template', function ()

describe('default filter', function()
it('overrides nil values', function()
local str = _M:new():interpret([[{{ nothing | default: "foo" }}]])

assert.equal(str, 'foo')
end)

it('overrides false values', function()
local str = _M:new():interpret([[{{ false | default: "foo" }}]])

assert.equal(str, 'false')
end)
end)

end)

0 comments on commit d1b258d

Please sign in to comment.