File tree Expand file tree Collapse file tree 3 files changed +13
-20
lines changed
lib/action_dispatch/journey Expand file tree Collapse file tree 3 files changed +13
-20
lines changed Original file line number Diff line number Diff line change 2
2
3
3
# :markup: markdown
4
4
5
+ require "cgi"
5
6
require "action_dispatch/journey/router/utils"
6
7
require "action_dispatch/journey/routes"
7
8
require "action_dispatch/journey/formatter"
@@ -123,8 +124,13 @@ def find_routes(req)
123
124
path_parameters = { }
124
125
index = 1
125
126
match_data . names . each do |name |
126
- val = match_data [ index ]
127
- path_parameters [ name . to_sym ] = Utils . unescape_uri ( val ) if val
127
+ if val = match_data [ index ]
128
+ path_parameters [ name . to_sym ] = if val . include? ( "%" )
129
+ CGI . unescapeURIComponent ( val )
130
+ else
131
+ val
132
+ end
133
+ end
128
134
index += 1
129
135
end
130
136
yield [ match_data , path_parameters , r ]
Original file line number Diff line number Diff line change @@ -61,11 +61,6 @@ def escape_segment(segment)
61
61
escape ( segment , SEGMENT )
62
62
end
63
63
64
- def unescape_uri ( uri )
65
- encoding = uri . encoding == US_ASCII ? UTF_8 : uri . encoding
66
- uri . gsub ( ESCAPED ) { |match | [ match [ 1 , 2 ] . hex ] . pack ( "C" ) } . force_encoding ( encoding )
67
- end
68
-
69
64
private
70
65
def escape ( component , pattern )
71
66
component . gsub ( pattern ) { |unsafe | percent_encode ( unsafe ) } . force_encoding ( US_ASCII )
@@ -91,14 +86,6 @@ def self.escape_segment(segment)
91
86
def self . escape_fragment ( fragment )
92
87
ENCODER . escape_fragment ( fragment . to_s )
93
88
end
94
-
95
- # Replaces any escaped sequences with their unescaped representations.
96
- #
97
- # uri = "/topics?title=Ruby%20on%20Rails"
98
- # unescape_uri(uri) #=> "/topics?title=Ruby on Rails"
99
- def self . unescape_uri ( uri )
100
- ENCODER . unescape_uri ( uri )
101
- end
102
89
end
103
90
end
104
91
end
Original file line number Diff line number Diff line change @@ -18,12 +18,12 @@ def test_fragment_escape
18
18
assert_equal "a/b%20c+d%25?e" , Utils . escape_fragment ( "a/b c+d%?e" )
19
19
end
20
20
21
- def test_uri_unescape
22
- assert_equal "a/b c+d" , Utils . unescape_uri ( "a%2Fb%20c+d" )
21
+ def test_CGI_unescapeURIComponent
22
+ assert_equal "a/b c+d" , CGI . unescapeURIComponent ( "a%2Fb%20c+d" )
23
23
end
24
24
25
- def test_uri_unescape_with_utf8_string
26
- assert_equal "Šašinková" , Utils . unescape_uri ( ( +"%C5%A0a%C5%A1inkov%C3%A1" ) . force_encoding ( Encoding ::US_ASCII ) )
25
+ def test_CGI_unescapeURIComponent_with_utf8_string
26
+ assert_equal "Šašinková" , CGI . unescapeURIComponent ( ( +"%C5%A0a%C5%A1inkov%C3%A1" ) . force_encoding ( Encoding ::US_ASCII ) )
27
27
end
28
28
29
29
def test_normalize_path_not_greedy
@@ -36,7 +36,7 @@ def test_normalize_path_uppercase
36
36
37
37
def test_normalize_path_maintains_string_encoding
38
38
path = "/foo%AAbar%AAbaz" . b
39
- assert_equal Encoding ::ASCII_8BIT , Utils . normalize_path ( path ) . encoding
39
+ assert_equal Encoding ::BINARY , Utils . normalize_path ( path ) . encoding
40
40
end
41
41
42
42
def test_normalize_path_with_nil
You can’t perform that action at this time.
0 commit comments