Strip extra slashes via `Jekyll.sanitized_path` (#7182)
Merge pull request 7182
This commit is contained in:
		
							parent
							
								
									ce05f9cb15
								
							
						
					
					
						commit
						6eee8b7e06
					
				|  | @ -176,6 +176,10 @@ module Jekyll | ||||||
| 
 | 
 | ||||||
|       return clean_path if clean_path.eql?(base_directory) |       return clean_path if clean_path.eql?(base_directory) | ||||||
| 
 | 
 | ||||||
|  |       # remove any remaining extra leading slashes not stripped away by calling | ||||||
|  |       # `File.expand_path` above. | ||||||
|  |       clean_path.squeeze!("/") | ||||||
|  | 
 | ||||||
|       if clean_path.start_with?(base_directory.sub(%r!\z!, "/")) |       if clean_path.start_with?(base_directory.sub(%r!\z!, "/")) | ||||||
|         clean_path |         clean_path | ||||||
|       else |       else | ||||||
|  |  | ||||||
|  | @ -31,6 +31,13 @@ class TestPathSanitization < JekyllUnitTest | ||||||
|                  Jekyll.sanitized_path(source_dir, "f./../../../../../../files/hi.txt") |                  Jekyll.sanitized_path(source_dir, "f./../../../../../../files/hi.txt") | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  |   should "strip extra slashes in questionable path" do | ||||||
|  |     subdir = "/files/" | ||||||
|  |     file_path = "/hi.txt" | ||||||
|  |     assert_equal source_dir("files", "hi.txt"), | ||||||
|  |                  Jekyll.sanitized_path(source_dir, "/#{subdir}/#{file_path}") | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|   if Jekyll::Utils::Platforms.really_windows? |   if Jekyll::Utils::Platforms.really_windows? | ||||||
|     context "on Windows with absolute path" do |     context "on Windows with absolute path" do | ||||||
|       setup do |       setup do | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue