Skip to content

Commit

Permalink
Handle undefined elements.
Browse files Browse the repository at this point in the history
  • Loading branch information
pashields committed Aug 1, 2013
1 parent 450ad68 commit b7ddcc5
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/zerkel-parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/zerkel-parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ numComp
= left:value optionalSpace op:numCompOp optionalSpace right:value { return left + op + right; }

contains
= left:value requiredSpace containsOp requiredSpace right:value { return "(" + left + ".indexOf(" + right + ")" + " >= 0)"; }
= left:value requiredSpace containsOp requiredSpace right:value { return "(" + left + "&&" + left + ".indexOf(" + right + ")" + " >= 0)"; }

like
= left:value requiredSpace likeOp requiredSpace right:value { return "_helpers['match'](" + left + "," + right + ")"; }
Expand Down
4 changes: 2 additions & 2 deletions src/zerkel.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports.match = match = (val, pattern) ->
pattern = val
val = pattern
if pattern == '*' then return true
if pattern[0] == '*' and pattern[pattern.length - 1] == '*'
if pattern[0] == '*' and pattern[pattern.length - 1] == '*'
pattern = pattern[1..-3]
return (val.indexOf(pattern) >= 0) and val.length > pattern.length + 1
if pattern[0] == '*'
Expand All @@ -20,4 +20,4 @@ module.exports.helpers = helpers = {match: match}
module.exports.compile = (query) ->
body = "return " + parser.parse(query)
fn = new Function('_helpers', '_env', body)
return (env) -> fn helpers, env
return (env) -> Boolean fn helpers, env
1 change: 1 addition & 0 deletions test/zerkel.tests.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ makeTest('((keywords contains "c#" and keywords contains "performance") or (keyw
makeTest '"foo" = x', {x: "foo"}, true
makeTest 'x like "foo*"', {x: "foobar"}, true
makeTest 'x like "foo*"', {x: "foo"}, false
makeTest 'array contains "Foo"', {}, false

makeTest = (a, b, expected) ->
it "#{a} like #{b} should be #{expected}", ->
Expand Down

0 comments on commit b7ddcc5

Please sign in to comment.