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

Changeset 7214

Show
Ignore:
Timestamp:
07/24/07 01:40:13 (1 year ago)
Author:
david
Message:

Use URI instead of regexps to normalize the URL and gain free, better matching (closes #8136) [dkubb]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/open_id_authentication/CHANGELOG

    r7162 r7214  
     1* Use URI instead of regexps to normalize the URL and gain free, better matching #8136 [dkubb] 
     2 
    13* Allow -'s in #normalize_url [Rick] 
    24 
  • plugins/open_id_authentication/lib/open_id_authentication.rb

    r7163 r7214  
    5858 
    5959  def self.normalize_url(url) 
    60     url = url.downcase 
    61    
    62     case url 
    63     when %r{^https?://[^/]+/[^/]*} 
    64       url # already normalized 
    65     when %r{^https?://[^/]+$} 
    66       url + "/" 
    67     when %r{^[.\d\w-]+/.*$} 
    68       "http://" + url 
    69     when %r{^[.\d\w-]+$} 
    70       "http://" + url + "/" 
    71     else 
     60    begin 
     61      uri = URI.parse(url) 
     62      uri = URI.parse("http://#{uri}") unless uri.scheme 
     63      uri.scheme = uri.scheme.downcase  # URI should do this 
     64      uri.normalize.to_s 
     65    rescue URI::InvalidURIError 
    7266      raise InvalidOpenId.new("#{url} is not an OpenID URL") 
    7367    end 
  • plugins/open_id_authentication/test/normalize_test.rb

    r7162 r7214  
    1010 
    1111  NORMALIZATIONS = { 
    12     "openid.aol.com/nextangler"         => "http://openid.aol.com/nextangler", 
    13     "http://openid.aol.com/nextangler"  => "http://openid.aol.com/nextangler", 
    14     "https://openid.aol.com/nextangler" => "https://openid.aol.com/nextangler", 
    15     "loudthinking.com"                  => "http://loudthinking.com/", 
    16     "http://loudthinking.com"           => "http://loudthinking.com/", 
    17     "techno-weenie.net"                 => "http://techno-weenie.net/", 
    18     "http://techno-weenie.net"          => "http://techno-weenie.net/" 
     12    "openid.aol.com/nextangler"             => "http://openid.aol.com/nextangler", 
     13    "http://openid.aol.com/nextangler"      => "http://openid.aol.com/nextangler", 
     14    "https://openid.aol.com/nextangler"     => "https://openid.aol.com/nextangler", 
     15    "HTTP://OPENID.AOL.COM/NEXTANGLER"      => "http://openid.aol.com/NEXTANGLER", 
     16    "HTTPS://OPENID.AOL.COM/NEXTANGLER"     => "https://openid.aol.com/NEXTANGLER", 
     17    "loudthinking.com"                      => "http://loudthinking.com/", 
     18    "http://loudthinking.com"               => "http://loudthinking.com/", 
     19    "http://loudthinking.com:80"            => "http://loudthinking.com/", 
     20    "https://loudthinking.com:443"          => "https://loudthinking.com/", 
     21    "http://loudthinking.com:8080"          => "http://loudthinking.com:8080/", 
     22    "techno-weenie.net"                     => "http://techno-weenie.net/", 
     23    "http://techno-weenie.net"              => "http://techno-weenie.net/" 
    1924  } 
    2025