[CMF-checkins] CVS: CMF/CMFDefault - Link.py:1.18

Florent Guillaume fg@nuxeo.com
Sun, 30 Jun 2002 06:20:24 -0400


Update of /cvs-repository/CMF/CMFDefault
In directory cvs.zope.org:/tmp/cvs-serv25384/CMFDefault

Modified Files:
	Link.py 
Log Message:
Corrected yesterday's code and testcases for Links (I brainfarted on
'foo.com' -> 'http://foo.com', thanks Yuppie for the heads up). We're
trying to canonicalize a URL here but sometimes we have no way to do it
completely (no nethost part).

Someone please review the tests (test_fixupMissingScheme,
test_trailingSlash) for correctness.


=== CMF/CMFDefault/Link.py 1.17 => 1.18 ===
         """
         tokens = urlparse.urlparse( remote_url, 'http' )
-        url = urlparse.urlunparse( tokens )
+        if tokens[1]:
+            # We have a nethost. All is well.
+            url = urlparse.urlunparse(tokens)
+        elif remote_url[:1] == '/':
+            # Starts with a slash, site-relative URL,
+            # no way to completely absolutize it.
+            url = urlparse.urlunparse(tokens)
+        else:
+            # Starts with a host without http:// qualification,
+            # add it correctly because urlparse didn't do it.
+            tokens = urlparse.urlparse('http://'+remote_url)
+            url = urlparse.urlunparse(tokens)
         if url == 'http:':
             url = ''
         self.remote_url = url