<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -19,16 +19,10 @@ module Html
         end
       end
 
-      def check_redirects_resolve
-        if response.status =~ /302/
-          if response.redirected_to.is_a?(Hash)
-            # redirected_to={:action=&gt;&quot;foobar&quot;}
-            url = url_from_params(response.redirected_to)
-          else
-            # redirected_to=&quot;http://test.host/foobar&quot;
-            url = response.redirected_to[%r{#{Regexp.escape(request.host)}(.+)$}, 1]
-          end
-          check_url_resolves(url)
+      def check_redirects_resolve        
+        redirect_url = response.headers['Location']
+        if response.status =~ /302/ &amp;&amp; redirect_url.present?
+          check_url_resolves(redirect_url)
         end
       end
 
@@ -38,12 +32,16 @@ module Html
       end
 
       def check_url_resolves(url)
-        return if url.blank? or skip_url?(url) or external_http?(url)
+        return if skip_url?(url, root_url) || external_http?(url, root_url)
         url = strip_anchor(remove_query(make_absolute(url)))
         return if public_file_exists?(url)
         check_action_exists(url)
       end
 
+      def root_url
+        request.protocol + request.host_with_port
+      end
+
       def public_file_exists?(url)
         public_path = File.join(rails_public_path, url)
         File.exists?(public_path) || File.exists?(public_path + &quot;.html&quot;)
@@ -53,14 +51,20 @@ module Html
         File.join(RAILS_ROOT, &quot;public&quot;)
       end
 
-      # Make relative URLs absolute, i.e. relative to the site root
+      # Make URLs absolute paths, i.e. relative to the site root
       def make_absolute(url)
+        url = remove_host(url) if has_protocol?(url)
         return url if url =~ %r{^/}
         current_url = request.request_uri || url_from_params
         current_url = File.dirname(current_url) if current_url !~ %r{/$}
         url = File.join(current_url, url) 
       end
 
+      def remove_host(url)
+        url_no_host = url[%r{^[a-z]+://[^/]+(/.+)$}, 1]
+        url_no_host.blank? ? &quot;/&quot; : url_no_host
+      end
+
       def remove_query(url)
         url =~ /\?/ ? url[/^(.+?)\?/, 1] : url
       end</diff>
      <filename>lib/url_checker.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,16 +1,36 @@
 module Html
   module Test
     module UrlSelector
-      def skip_url?(url)
-        return true if url.blank? or (!external_http?(url) and url =~ /:\/\//) # Unsupported protocol
-        [/^javascript:/, /^mailto:/, /^\#$/].each do |pattern|
-          return true if url =~ pattern
+      def skip_url?(url, root_url = nil)
+        if url.blank? || unsupported_protocol?(url) || special_url?(url)
+          true
+        else
+          false
         end
-        false
       end
 
-      def external_http?(url)
-         url =~ /^http(?:s)?:\/\//
+      def special_url?(url)
+        [/^javascript:/, /^mailto:/, /^\#$/].any? { |pattern| url =~ pattern }
+      end
+
+      def external_http?(url, root_url = nil)
+        if root_url
+          http_protocol?(url) &amp;&amp; !url.starts_with?(root_url)
+        else
+          http_protocol?(url)
+        end
+      end
+
+      def http_protocol?(url)
+        url =~ %r{^http(?:s)?://} ? true : false
+      end
+
+      def has_protocol?(url)
+        url =~ %r{^[a-z]+://} ? true : false
+      end
+
+      def unsupported_protocol?(url)
+        has_protocol?(url) &amp;&amp; !http_protocol?(url)
       end
 
       def anchor_urls</diff>
      <filename>lib/url_selector.rb</filename>
    </modified>
    <modified>
      <diff>@@ -82,6 +82,16 @@ class Html::Test::ControllerTest &lt; ActionController::TestCase
     assert_response :redirect
   end
 
+  def test_redirect_external
+    get :redirect_external
+    assert_response :redirect
+  end
+
+  def test_redirect_valid_with_host
+    get :redirect_valid_with_host
+    assert_response :redirect    
+  end
+
   def test_image_file_exists
     get :image_file_exists
     assert_response :success</diff>
      <filename>test/controller_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -30,6 +30,14 @@ class TestController &lt; ActionController::Base
     redirect_to :action =&gt; 'valid'
   end
 
+  def redirect_external
+    redirect_to &quot;http://google.com/foobar&quot;
+  end
+
+  def redirect_valid_with_host
+    redirect_to &quot;http://test.host/test/valid&quot;
+  end
+
   def image_file_exists
     render :text =&gt; %Q{&lt;img src=&quot;/image.jpg?23049829034&quot;/&gt;}
   end</diff>
      <filename>test/test_helper.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>69fd7bb935417b3b2b1af14970fb54fb7c7fe1e0</id>
    </parent>
  </parents>
  <author>
    <name>Peter Marklund</name>
    <email>peter_marklund@fastmail.fm</email>
  </author>
  <url>http://github.com/peter/html_test/commit/1b307b5b791056d09cbee8c59c8ee34823406baa</url>
  <id>1b307b5b791056d09cbee8c59c8ee34823406baa</id>
  <committed-date>2009-05-20T10:09:55-07:00</committed-date>
  <authored-date>2009-05-20T10:09:55-07:00</authored-date>
  <message>Making check_redirects_resolve be based on headers['Location'] rather than the argument that the redirect_to command receives. This way it works regardless of what you pass to redirect_to (a hash, a URL, an ActiveRecord object etc.). Cleaning up a few methods in url_checker and url_selector related to skipping URLs and now also making sure we drop the procotol/host since it may be in the URL</message>
  <tree>942f7d67002a4bf8217bb1a75c3e136e1ad1a5a3</tree>
  <committer>
    <name>Peter Marklund</name>
    <email>peter_marklund@fastmail.fm</email>
  </committer>
</commit>
