Index: test/normalize_test.rb
===================================================================
--- test/normalize_test.rb	(revision 7117)
+++ test/normalize_test.rb	(working copy)
@@ -9,11 +9,16 @@
   include OpenIdAuthentication
 
   NORMALIZATIONS = {
-    "openid.aol.com/nextangler"         => "http://openid.aol.com/nextangler",
-    "http://openid.aol.com/nextangler"  => "http://openid.aol.com/nextangler",
-    "https://openid.aol.com/nextangler" => "https://openid.aol.com/nextangler",
-    "loudthinking.com"                  => "http://loudthinking.com/",
-    "http://loudthinking.com"           => "http://loudthinking.com/"
+    "openid.aol.com/nextangler"             => "http://openid.aol.com/nextangler",
+    "http://openid.aol.com/nextangler"      => "http://openid.aol.com/nextangler",
+    "https://openid.aol.com/nextangler"     => "https://openid.aol.com/nextangler",
+    "HTTP://OPENID.AOL.COM/NEXTANGLER"      => "http://openid.aol.com/NEXTANGLER",
+    "HTTPS://OPENID.AOL.COM/NEXTANGLER"     => "https://openid.aol.com/NEXTANGLER",
+    "loudthinking.com"                      => "http://loudthinking.com/",
+    "http://loudthinking.com"               => "http://loudthinking.com/",
+    "http://loudthinking.com:80"            => "http://loudthinking.com/",
+    "https://loudthinking.com:443"          => "https://loudthinking.com/",
+    "http://loudthinking.com:8080"          => "http://loudthinking.com:8080/",
   }
 
   def test_normalizations
Index: test/open_id_authentication_test.rb
===================================================================
--- test/open_id_authentication_test.rb	(revision 7117)
+++ test/open_id_authentication_test.rb	(working copy)
@@ -28,7 +28,7 @@
   end
 
   def test_authentication_should_fail_when_the_identity_server_times_out
-    @controller.stubs(:open_id_consumer).returns(stub(:begin => Proc.new { raise Timeout::Error }))
+    @controller.stubs(:open_id_consumer).returns(stub(:begin => Proc.new { raise Timeout::Error, 'timed out' }))
 
     @controller.send(:authenticate_with_open_id, "http://someone.example.com") do |result, identity_url|
       assert result.missing?
Index: lib/open_id_authentication.rb
===================================================================
--- lib/open_id_authentication.rb	(revision 7117)
+++ lib/open_id_authentication.rb	(working copy)
@@ -46,18 +46,12 @@
   end
 
   def self.normalize_url(url)
-    url = url.downcase
-  
-    case url
-    when %r{^https?://[^/]+/[^/]*}
-      url # already normalized
-    when %r{^https?://[^/]+$}
-      url + "/"
-    when %r{^[.\d\w]+/.*$}
-      "http://" + url
-    when %r{^[.\d\w]+$}
-      "http://" + url + "/"
-    else
+    begin
+      uri = URI.parse(url)
+      uri = URI.parse("http://#{uri}") unless uri.scheme
+      uri.scheme = uri.scheme.downcase  # URI should do this
+      uri.normalize.to_s
+    rescue URI::InvalidURIError
       raise InvalidOpenId.new("#{url} is not an OpenID URL")
     end
   end
