Permalink
Browse files

change route regex to string beginning and end

  • Loading branch information...
1 parent 1133c41 commit 8ff98ff9dd6fef4007f5be9d79d68368509094fd @Gibheer Gibheer committed Feb 11, 2013
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/zero/router.rb
View
@@ -21,6 +21,10 @@ class Router
VARIABLE_MATCH = %r{:(\w+)[^/]?}
# the replacement string to make it an regex
VARIABLE_REGEX = '(?<\1>.+?)'
+ # regex part of the beginning of the line
+ REGEX_BEGINNING = '\A'
+ # regex part of the end of the line
+ REGEX_END = '\Z'
# environment key to store custom parameters
ENV_KEY_CUSTOM = 'zero.params.custom'
# environment key to the path info
@@ -39,8 +43,9 @@ def initialize(routes)
@routes = {}
routes.each do |route, target|
@routes[
- Regexp.new(
- '^' + route.gsub(VARIABLE_MATCH, VARIABLE_REGEX) + '$')] = target
+ Regexp.new(REGEX_BEGINNING +
+ route.gsub(VARIABLE_MATCH, VARIABLE_REGEX) +
+ REGEX_END)] = target
end
end

0 comments on commit 8ff98ff

Please sign in to comment.