mirror of
				https://github.com/python/cpython.git
				synced 2025-10-26 03:04:41 +00:00 
			
		
		
		
	Merged revisions 80277 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r80277 | senthil.kumaran | 2010-04-21 02:07:59 +0530 (Wed, 21 Apr 2010) | 3 lines Issue2987 - Added additional Invalid URL and changed the Invalid URL checking code for better. ........
This commit is contained in:
		
							parent
							
								
									712979d292
								
							
						
					
					
						commit
						2eaef05c47
					
				
					 2 changed files with 9 additions and 6 deletions
				
			
		|  | @ -273,6 +273,7 @@ def test_RFC2732(self): | ||||||
|         for invalid_url in [ |         for invalid_url in [ | ||||||
|                 'http://::12.34.56.78]/', |                 'http://::12.34.56.78]/', | ||||||
|                 'http://[::1/foo/', |                 'http://[::1/foo/', | ||||||
|  |                 'http://[::1/foo/bad]/bad', | ||||||
|                 'http://[::ffff:12.34.56.78']: |                 'http://[::ffff:12.34.56.78']: | ||||||
|             self.assertRaises(ValueError, lambda : urllib.parse.urlparse(invalid_url).hostname) |             self.assertRaises(ValueError, lambda : urllib.parse.urlparse(invalid_url).hostname) | ||||||
|             self.assertRaises(ValueError, lambda : urllib.parse.urlparse(invalid_url)) |             self.assertRaises(ValueError, lambda : urllib.parse.urlparse(invalid_url)) | ||||||
|  |  | ||||||
|  | @ -95,8 +95,6 @@ def hostname(self): | ||||||
|         netloc = self.netloc.split('@')[-1] |         netloc = self.netloc.split('@')[-1] | ||||||
|         if '[' in netloc and ']' in netloc: |         if '[' in netloc and ']' in netloc: | ||||||
|             return netloc.split(']')[0][1:].lower() |             return netloc.split(']')[0][1:].lower() | ||||||
|         elif '[' in netloc or ']' in netloc: |  | ||||||
|             raise ValueError("Invalid IPv6 hostname") |  | ||||||
|         elif ':' in netloc: |         elif ':' in netloc: | ||||||
|             return netloc.split(':')[0].lower() |             return netloc.split(':')[0].lower() | ||||||
|         elif netloc == '': |         elif netloc == '': | ||||||
|  | @ -156,10 +154,6 @@ def _splitparams(url): | ||||||
| 
 | 
 | ||||||
| def _splitnetloc(url, start=0): | def _splitnetloc(url, start=0): | ||||||
|     delim = len(url)   # position of end of domain part of url, default is end |     delim = len(url)   # position of end of domain part of url, default is end | ||||||
|     if '[' in url:     # check for invalid IPv6 URL |  | ||||||
|         if not ']' in url: raise ValueError("Invalid IPv6 URL") |  | ||||||
|     elif ']' in url: |  | ||||||
|         if not '[' in url: raise ValueError("Invalid IPv6 URL") |  | ||||||
|     for c in '/?#':    # look for delimiters; the order is NOT important |     for c in '/?#':    # look for delimiters; the order is NOT important | ||||||
|         wdelim = url.find(c, start)        # find first of this delim |         wdelim = url.find(c, start)        # find first of this delim | ||||||
|         if wdelim >= 0:                    # if found |         if wdelim >= 0:                    # if found | ||||||
|  | @ -187,6 +181,10 @@ def urlsplit(url, scheme='', allow_fragments=True): | ||||||
|             url = url[i+1:] |             url = url[i+1:] | ||||||
|             if url[:2] == '//': |             if url[:2] == '//': | ||||||
|                 netloc, url = _splitnetloc(url, 2) |                 netloc, url = _splitnetloc(url, 2) | ||||||
|  |                 if '[' in netloc : | ||||||
|  |                     if not ']' in netloc: raise ValueError("Invalid IPv6 URL") | ||||||
|  |                 if ']' in netloc: | ||||||
|  |                     if not '[' in netloc: raise ValueError("Invalid IPv6 URL") | ||||||
|             if allow_fragments and '#' in url: |             if allow_fragments and '#' in url: | ||||||
|                 url, fragment = url.split('#', 1) |                 url, fragment = url.split('#', 1) | ||||||
|             if '?' in url: |             if '?' in url: | ||||||
|  | @ -201,6 +199,10 @@ def urlsplit(url, scheme='', allow_fragments=True): | ||||||
|             scheme, url = url[:i].lower(), url[i+1:] |             scheme, url = url[:i].lower(), url[i+1:] | ||||||
|     if url[:2] == '//': |     if url[:2] == '//': | ||||||
|         netloc, url = _splitnetloc(url, 2) |         netloc, url = _splitnetloc(url, 2) | ||||||
|  |         if '[' in netloc: | ||||||
|  |             if not ']' in netloc: raise ValueError("Invalid IPv6 URL") | ||||||
|  |         if ']' in netloc: | ||||||
|  |             if not '[' in netloc: raise ValueError("Invalid IPv6 URL") | ||||||
|     if allow_fragments and scheme in uses_fragment and '#' in url: |     if allow_fragments and scheme in uses_fragment and '#' in url: | ||||||
|         url, fragment = url.split('#', 1) |         url, fragment = url.split('#', 1) | ||||||
|     if scheme in uses_query and '?' in url: |     if scheme in uses_query and '?' in url: | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Senthil Kumaran
						Senthil Kumaran