Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8546: dont_escape_redirect_urls.diff

File dont_escape_redirect_urls.diff, 2.5 kB (added by josh, 2 years ago)
  • actionpack/test/controller/redirect_test.rb

    old new  
    3737    redirect_to :action => "hello_world" 
    3838  end 
    3939 
     40  def redirect_to_url 
     41    redirect_to "http://www.rubyonrails.org/" 
     42  end 
     43 
     44  def redirect_to_url_with_unescaped_query_string 
     45    redirect_to "http://dev.rubyonrails.org/query?status=new" 
     46  end 
     47 
    4048  def redirect_to_back 
    4149    redirect_to :back 
    4250  end 
     
    111119    assert_equal "world", assigns["hello"] 
    112120  end 
    113121 
     122  def test_redirect_to_url 
     123    get :redirect_to_url 
     124    assert_response :redirect 
     125    assert_redirected_to "http://www.rubyonrails.org/" 
     126  end 
     127 
     128  def test_redirect_to_url_with_unescaped_query_string 
     129    get :redirect_to_url_with_unescaped_query_string 
     130    assert_response :redirect 
     131    assert_redirected_to "http://dev.rubyonrails.org/query?status=new" 
     132  end 
     133 
    114134  def test_redirect_to_back 
    115135    @request.env["HTTP_REFERER"] = "http://www.example.com/coming/from" 
    116136    get :redirect_to_back 
  • actionpack/test/template/prototype_helper_test.rb

    old new  
    314314  def test_redirect_to 
    315315    assert_equal 'window.location.href = "http://www.example.com/welcome";', 
    316316      @generator.redirect_to(:action => 'welcome') 
     317    assert_equal 'window.location.href = "http://www.example.com/welcome?a=b&c=d";', 
     318      @generator.redirect_to("http://www.example.com/welcome?a=b&c=d") 
    317319  end 
    318320   
    319321  def test_delay 
  • actionpack/lib/action_view/helpers/prototype_helper.rb

    old new  
    554554           
    555555          # Redirects the browser to the given +location+, in the same form as +url_for+. 
    556556          def redirect_to(location) 
    557             assign 'window.location.href', @context.url_for(location) 
     557            url = location.is_a?(String) ? location : @context.url_for(location) 
     558            assign 'window.location.href', url 
    558559          end 
    559560           
    560561          # Calls the JavaScript +function+, optionally with the given +arguments+.