File tree Expand file tree Collapse file tree 2 files changed +37
-5
lines changed
lib/action_controller/metal Expand file tree Collapse file tree 2 files changed +37
-5
lines changed Original file line number Diff line number Diff line change @@ -637,16 +637,22 @@ def normalize_action_path(action_path) # :doc:
637
637
uri = URI . parse ( action_path )
638
638
639
639
if uri . relative? && ( action_path . blank? || !action_path . start_with? ( "/" ) )
640
- uri = URI . parse ( request . path )
641
- # add the action path to the request.path
642
- uri . path += "/#{ action_path } "
643
- # relative path with "./path"
644
- uri . path . gsub! ( "/./" , "/" )
640
+ return normalize_relative_action_path ( uri . path )
645
641
end
646
642
647
643
uri . path . chomp ( "/" )
648
644
end
649
645
646
+ def normalize_relative_action_path ( rel_action_path ) # :doc:
647
+ uri = URI . parse ( request . path )
648
+ # add the action path to the request.path
649
+ uri . path += "/#{ rel_action_path } "
650
+ # relative path with "./path"
651
+ uri . path . gsub! ( "/./" , "/" )
652
+
653
+ uri . path . chomp ( "/" )
654
+ end
655
+
650
656
def generate_csrf_token # :nodoc:
651
657
SecureRandom . urlsafe_base64 ( AUTHENTICITY_TOKEN_LENGTH )
652
658
end
Original file line number Diff line number Diff line change @@ -1151,6 +1151,32 @@ def test_handles_relative_paths_with_dot
1151
1151
assert_response :success
1152
1152
end
1153
1153
1154
+ def test_handles_query_string
1155
+ get :index , params : { form_path : "./post_one?a=b" }
1156
+
1157
+ form_token = assert_presence_and_fetch_form_csrf_token
1158
+
1159
+ # This is required because PATH_INFO isn't reset between requests.
1160
+ @request . env [ "PATH_INFO" ] = "/per_form_tokens/post_one"
1161
+ assert_nothing_raised do
1162
+ post :post_one , params : { custom_authenticity_token : form_token }
1163
+ end
1164
+ assert_response :success
1165
+ end
1166
+
1167
+ def test_handles_fragment
1168
+ get :index , params : { form_path : "./post_one#a" }
1169
+
1170
+ form_token = assert_presence_and_fetch_form_csrf_token
1171
+
1172
+ # This is required because PATH_INFO isn't reset between requests.
1173
+ @request . env [ "PATH_INFO" ] = "/per_form_tokens/post_one"
1174
+ assert_nothing_raised do
1175
+ post :post_one , params : { custom_authenticity_token : form_token }
1176
+ end
1177
+ assert_response :success
1178
+ end
1179
+
1154
1180
def test_ignores_origin_during_generation
1155
1181
get :index , params : { form_path : "https://example.com/per_form_tokens/post_one/" }
1156
1182
You can’t perform that action at this time.
0 commit comments