Skip to content

Commit

Permalink
Simplified default parser function so it wont validate lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
tarruda committed Aug 30, 2012
1 parent b6401bb commit ae73514
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/router.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@ absoluteUrl = (req, pathname, search) ->
return rv.join('')


# The most basic parameter parser, which ensures no slashes
# in the string and can optionally validate string length.
# The most basic parameter parser, used when no parser is specified.
# It only ensures that no slashes will be in the string.
defaultParser = (str, opts) ->
if str.indexOf('/') != -1
return null
if opts
if (isFinite(opts.len) && str.length != opts.len) ||
(isFinite(opts.min) && str.length < opts.min) ||
(isFinite(opts.max) && str.length > opts.max)
return null
return str


Expand Down Expand Up @@ -118,7 +113,14 @@ class Compiler
return null
return rv

str: (str, opts) -> defaultParser(str, opts)
str: (str, opts) ->
if defaultParser(str) == null then return null
if opts
if (isFinite(opts.len) && str.length != opts.len) ||
(isFinite(opts.min) && str.length < opts.min) ||
(isFinite(opts.max) && str.length > opts.max)
return null
return str

path: (str) -> str

Expand Down

0 comments on commit ae73514

Please sign in to comment.