diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-25 11:25:36 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-25 11:25:36 -0700 |
commit | e2fd64fe469037644711a65a00270bea15ee2955 (patch) | |
tree | a7374d295e2f8e137593171ae99d2d6102d868bc /actionpack/lib/action_dispatch/journey | |
parent | 70e48a6ac34615ba5ed3b807917c3b099256d67c (diff) | |
parent | f3982858359008ec8fe43b8fa2c75aad8788cd89 (diff) | |
download | rails-e2fd64fe469037644711a65a00270bea15ee2955.tar.gz rails-e2fd64fe469037644711a65a00270bea15ee2955.tar.bz2 rails-e2fd64fe469037644711a65a00270bea15ee2955.zip |
Merge branch 'master' into preload
* master: (62 commits)
Getting Started Guide: Hello Rails! -> Hello, Rails! and wrap code tag
Add CHANGELOG entry for #12344
Add regression test to #12343
Fix typo in number_to_human docs: you -> your
[Documentation] Add a missing validation to I18n docs
Use the given name in html_options for the hidden field in collection_check_boxes
assign_attributes should return if argument is blank.
No need the else clause
Use join to concat the both side of the AST
Add a CHANGELOG entry about Web Console inclusion
added column type to example in section 2.3
Include web-console in new projects Gemfile
ActiveRecord::ConnectionAdapters::Column.string_to_time method respects string with timezone. Closes #12278.
add test_scoped_root_as_name
Getting Started Guide: update RubyGems Guides link [ci skip]
Deprecate unused quoted_locking_column method.
Update references to wycats/thor to erikhuda/thor.
bcrypt-ruby v3.1.2 supports Ruby 2.0 on Windows
Fix the model name in the association basics guides
We shouldn't override PostgreSQLAdapter's superclass inheritance while monkeypatching
...
Diffstat (limited to 'actionpack/lib/action_dispatch/journey')
-rw-r--r-- | actionpack/lib/action_dispatch/journey/router/utils.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/journey/visitors.rb | 45 |
2 files changed, 25 insertions, 24 deletions
diff --git a/actionpack/lib/action_dispatch/journey/router/utils.rb b/actionpack/lib/action_dispatch/journey/router/utils.rb index 80011597aa..1edf86cd88 100644 --- a/actionpack/lib/action_dispatch/journey/router/utils.rb +++ b/actionpack/lib/action_dispatch/journey/router/utils.rb @@ -7,11 +7,13 @@ module ActionDispatch # Normalizes URI path. # # Strips off trailing slash and ensures there is a leading slash. + # Also converts downcase url encoded string to uppercase. # # normalize_path("/foo") # => "/foo" # normalize_path("/foo/") # => "/foo" # normalize_path("foo") # => "/foo" # normalize_path("") # => "/" + # normalize_path("/%ab") # => "/%AB" def self.normalize_path(path) path = "/#{path}" path.squeeze!('/') @@ -36,7 +38,7 @@ module ActionDispatch UNSAFE_FRAGMENT = Regexp.new("[^#{safe_fragment}]", false).freeze end - Parser = URI.const_defined?(:Parser) ? URI::Parser.new : URI + Parser = URI::Parser.new def self.escape_path(path) Parser.escape(path.to_s, UriEscape::UNSAFE_SEGMENT) diff --git a/actionpack/lib/action_dispatch/journey/visitors.rb b/actionpack/lib/action_dispatch/journey/visitors.rb index 0a8cb1b4d4..a5b4679fae 100644 --- a/actionpack/lib/action_dispatch/journey/visitors.rb +++ b/actionpack/lib/action_dispatch/journey/visitors.rb @@ -84,44 +84,43 @@ module ActionDispatch # Used for formatting urls (url_for) class Formatter < Visitor # :nodoc: - attr_reader :options, :consumed + attr_reader :options def initialize(options) @options = options - @consumed = {} end private - def visit_GROUP(node) - if consumed == options - nil - else - route = visit(node.left) - route.include?("\0") ? nil : route + def visit(node, optional = false) + case node.type + when :LITERAL, :SLASH, :DOT + node.left + when :STAR + visit(node.left) + when :GROUP + visit(node.left, true) + when :CAT + visit_CAT(node, optional) + when :SYMBOL + visit_SYMBOL(node) end end - def terminal(node) - node.left - end - - def binary(node) - [visit(node.left), visit(node.right)].join - end + def visit_CAT(node, optional) + left = visit(node.left, optional) + right = visit(node.right, optional) - def nary(node) - node.children.map { |c| visit(c) }.join + if optional && !(right && left) + "" + else + [left, right].join + end end def visit_SYMBOL(node) - key = node.to_sym - - if value = options[key] - consumed[key] = value + if value = options[node.to_sym] Router::Utils.escape_path(value) - else - "\0" end end end |