diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-23 17:14:30 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-23 17:14:30 -0800 |
commit | 8d26f875f70beef3062deb5ded9c5ffcd473d5ac (patch) | |
tree | d1c1f4be7ae4eb3ba753e445f92381f993e8043a /actionpack/lib | |
parent | bce3b5cb72e61d855cdc924038a09b258bfcdf0c (diff) | |
download | rails-8d26f875f70beef3062deb5ded9c5ffcd473d5ac.tar.gz rails-8d26f875f70beef3062deb5ded9c5ffcd473d5ac.tar.bz2 rails-8d26f875f70beef3062deb5ded9c5ffcd473d5ac.zip |
Added custom regexps to ASTs that have literal nodes on either side of
symbol nodes. Fixes #4585
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/route_set.rb | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 2c21887220..6100e69d4b 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -360,7 +360,26 @@ module ActionDispatch SEPARATORS, anchor) - Journey::Path::Pattern.new(strexp) + pattern = Journey::Path::Pattern.new(strexp) + + builder = Journey::GTG::Builder.new pattern.spec + + # Get all the symbol nodes followed by literals that are not the + # dummy node. + symbols = pattern.spec.grep(Journey::Nodes::Symbol).find_all { |n| + builder.followpos(n).first.literal? + } + + # Get all the symbol nodes preceded by literals. + symbols.concat pattern.spec.find_all(&:literal?).map { |n| + builder.followpos(n).first + }.find_all(&:symbol?) + + symbols.each { |x| + x.regexp = /(?:#{Regexp.union(x.regexp, '-')})+/ + } + + pattern end private :build_path |