mirror of
				https://github.com/yt-dlp/yt-dlp.git
				synced 2025-10-30 22:25:19 +00:00 
			
		
		
		
	[utils] sanitize_path: Fix some incorrect behavior (#11923)
				
					
				
			Authored by: Grub4K
This commit is contained in:
		| @@ -249,17 +249,36 @@ class TestUtil(unittest.TestCase): | ||||
|         self.assertEqual(sanitize_path('abc/def...'), 'abc\\def..#') | ||||
|         self.assertEqual(sanitize_path('abc.../def'), 'abc..#\\def') | ||||
|         self.assertEqual(sanitize_path('abc.../def...'), 'abc..#\\def..#') | ||||
| 
 | ||||
|         self.assertEqual(sanitize_path('../abc'), '..\\abc') | ||||
|         self.assertEqual(sanitize_path('../../abc'), '..\\..\\abc') | ||||
|         self.assertEqual(sanitize_path('./abc'), 'abc') | ||||
|         self.assertEqual(sanitize_path('./../abc'), '..\\abc') | ||||
| 
 | ||||
|         self.assertEqual(sanitize_path('\\abc'), '\\abc') | ||||
|         self.assertEqual(sanitize_path('C:abc'), 'C:abc') | ||||
|         self.assertEqual(sanitize_path('C:abc\\..\\'), 'C:..') | ||||
|         self.assertEqual(sanitize_path('C:\\abc:%(title)s.%(ext)s'), 'C:\\abc#%(title)s.%(ext)s') | ||||
| 
 | ||||
|         # Check with nt._path_normpath if available | ||||
|         try: | ||||
|             import nt | ||||
| 
 | ||||
|             nt_path_normpath = getattr(nt, '_path_normpath', None) | ||||
|         except Exception: | ||||
|             nt_path_normpath = None | ||||
| 
 | ||||
|         for test, expected in [ | ||||
|             ('C:\\', 'C:\\'), | ||||
|             ('../abc', '..\\abc'), | ||||
|             ('../../abc', '..\\..\\abc'), | ||||
|             ('./abc', 'abc'), | ||||
|             ('./../abc', '..\\abc'), | ||||
|             ('\\abc', '\\abc'), | ||||
|             ('C:abc', 'C:abc'), | ||||
|             ('C:abc\\..\\', 'C:'), | ||||
|             ('C:abc\\..\\def\\..\\..\\', 'C:..'), | ||||
|             ('C:\\abc\\xyz///..\\def\\', 'C:\\abc\\def'), | ||||
|             ('abc/../', '.'), | ||||
|             ('./abc/../', '.'), | ||||
|         ]: | ||||
|             result = sanitize_path(test) | ||||
|             assert result == expected, f'{test} was incorrectly resolved' | ||||
|             assert result == sanitize_path(result), f'{test} changed after sanitizing again' | ||||
|             if nt_path_normpath: | ||||
|                 assert result == nt_path_normpath(test), f'{test} does not match nt._path_normpath' | ||||
| 
 | ||||
|     def test_sanitize_url(self): | ||||
|         self.assertEqual(sanitize_url('//foo.bar'), 'http://foo.bar') | ||||
|         self.assertEqual(sanitize_url('httpss://foo.bar'), 'https://foo.bar') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Simon Sawicki
					Simon Sawicki