Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source
Show
Ignore:
Timestamp:
03/28/08 20:01:21 (6 months ago)
Author:
david
Message:

Added support for regexp flags like ignoring case in the :requirements part of routes declarations (closes #11421) [NeilW]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_controller/routing/builder.rb

    r8652 r9115  
    1515      def interval_regexp 
    1616        Regexp.new "(.*?)(#{separators.source}|$)" 
     17      end 
     18 
     19      def multiline_regexp?(expression) 
     20        expression.options & Regexp::MULTILINE == Regexp::MULTILINE 
    1721      end 
    1822 
     
    99103            if requirement.source =~ %r{\A(\\A|\^)|(\\Z|\\z|\$)\Z} 
    100104              raise ArgumentError, "Regexp anchor characters are not allowed in routing requirements: #{requirement.inspect}" 
     105            end 
     106            if multiline_regexp?(requirement) 
     107              raise ArgumentError, "Regexp multiline option not allowed in routing requirements: #{requirement.inspect}" 
    101108            end 
    102109            segment.regexp = requirement 
  • trunk/actionpack/lib/action_controller/routing/route.rb

    r8652 r9115  
    6363        requirement_conditions = requirements.collect do |key, req| 
    6464          if req.is_a? Regexp 
    65             value_regexp = Regexp.new "\\A#{req.source}\\Z" 
     65            value_regexp = Regexp.new "\\A#{req.to_s}\\Z" 
    6666            "hash[:#{key}] && #{value_regexp.inspect} =~ options[:#{key}]" 
    6767          else 
  • trunk/actionpack/lib/action_controller/routing/segments.rb

    r8652 r9115  
    172172 
    173173      def value_regexp 
    174         Regexp.new "\\A#{regexp.source}\\Z" if regexp 
    175       end 
    176       def regexp_chunk 
    177         regexp ? "(#{regexp.source})" : "([^#{Routing::SEPARATORS.join}]+)" 
     174        Regexp.new "\\A#{regexp.to_s}\\Z" if regexp 
     175      end 
     176 
     177      def regexp_chunk 
     178        if regexp  
     179          if regexp_has_modifiers? 
     180            "(#{regexp.to_s})" 
     181          else 
     182            "(#{regexp.source})" 
     183          end 
     184        else 
     185          "([^#{Routing::SEPARATORS.join}]+)" 
     186        end 
    178187      end 
    179188 
     
    184193        optional? ? Regexp.optionalize(pattern) : pattern 
    185194      end 
     195 
    186196      def match_extraction(next_capture) 
    187197        # All non code-related keys (such as :id, :slug) are URI-unescaped as 
     
    202212      end 
    203213 
     214      def regexp_has_modifiers? 
     215        regexp.options & (Regexp::IGNORECASE | Regexp::EXTENDED) != 0 
     216      end 
     217 
    204218    end 
    205219