Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source
Show
Ignore:
Files:

Legend:

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

    r6729 r6730  
    249249  # 
    250250  module Routing 
     251    # TODO: , (comma) should be an allowed path character. 
    251252    SEPARATORS = %w( / ; . , ? ) 
    252253 
     
    548549 
    549550    class Segment #:nodoc: 
     551      # TODO: , (comma) should be an allowed path character. 
     552      RESERVED_PCHAR = ':@&=+$' 
     553      UNSAFE_PCHAR = Regexp.new("[^#{URI::REGEXP::PATTERN::UNRESERVED}#{RESERVED_PCHAR}]", false, 'N').freeze 
     554 
    550555      attr_accessor :is_optional 
    551556      alias_method :optional?, :is_optional 
     
    568573        end 
    569574      end 
    570    
     575 
     576      def interpolation_chunk 
     577        URI.escape(value, UNSAFE_PCHAR) 
     578      end 
     579 
    571580      # Return a string interpolation statement for this segment and those before it. 
    572581      def interpolation_statement(prior_segments) 
     
    612621   
    613622      def interpolation_chunk 
    614         raw? ? value : URI.escape(value) 
     623        raw? ? value : super 
    615624      end 
    616625   
    617626      def regexp_chunk 
    618         chunk = Regexp.escape value 
     627        chunk = Regexp.escape(value) 
    619628        optional? ? Regexp.optionalize(chunk) : chunk 
    620629      end 
     
    693702   
    694703      def interpolation_chunk 
    695         "\#{CGI.escape(#{local_name}.to_s)}" 
     704        "\#{URI.escape(#{local_name}.to_s, ActionController::Routing::Segment::UNSAFE_PCHAR)}" 
    696705      end 
    697706   
     
    724733      end 
    725734      def match_extraction(next_capture) 
    726         # All non code-related keys (such as :id, :slug) have to be unescaped as other CGI params 
     735        # All non code-related keys (such as :id, :slug) are URI-unescaped as 
     736        # path parameters. 
    727737        default_value = default ? default.inspect : nil 
    728738        %[ 
    729739          value = if (m = match[#{next_capture}]) 
    730             m = m.gsub('+', '%2B') 
    731             CGI.unescape(m) 
     740            URI.unescape(m) 
    732741          else 
    733742            #{default_value} 
     
    749758      end 
    750759 
    751       # Don't URI.escape the controller name, since it may have slashes in it, 
    752       # like admin/foo. 
     760      # Don't URI.escape the controller name since it may contain slashes. 
    753761      def interpolation_chunk 
    754762        "\#{#{local_name}.to_s}" 
     
    771779 
    772780    class PathSegment < DynamicSegment #:nodoc: 
    773       EscapedSlash = URI.escape("/") 
     781      RESERVED_PCHAR = "#{Segment::RESERVED_PCHAR}/" 
     782      UNSAFE_PCHAR = Regexp.new("[^#{URI::REGEXP::PATTERN::UNRESERVED}#{RESERVED_PCHAR}]", false, 'N').freeze 
     783 
    774784      def interpolation_chunk 
    775         "\#{URI.escape(#{local_name}.to_s).gsub(#{EscapedSlash.inspect}, '/')}" 
     785        "\#{URI.escape(#{local_name}.to_s, ActionController::Routing::PathSegment::UNSAFE_PCHAR)}" 
    776786      end 
    777787