 Chromium Code Reviews
 Chromium Code Reviews Issue 1704163003:
  FileURLToFilePath:  Don't unescape '/' and '\\'.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1704163003:
  FileURLToFilePath:  Don't unescape '/' and '\\'.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "net/base/filename_util.h" | 5 #include "net/base/filename_util.h" | 
| 6 | 6 | 
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" | 
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" | 
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" | 
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" | 
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 FileCase url_cases[] = { | 232 FileCase url_cases[] = { | 
| 233 #if defined(OS_WIN) | 233 #if defined(OS_WIN) | 
| 234 {L"C:\\foo\\bar.txt", "file:c|/foo\\bar.txt"}, | 234 {L"C:\\foo\\bar.txt", "file:c|/foo\\bar.txt"}, | 
| 235 {L"C:\\foo\\bar.txt", "file:/c:/foo/bar.txt"}, | 235 {L"C:\\foo\\bar.txt", "file:/c:/foo/bar.txt"}, | 
| 236 {L"\\\\foo\\bar.txt", "file://foo\\bar.txt"}, | 236 {L"\\\\foo\\bar.txt", "file://foo\\bar.txt"}, | 
| 237 {L"C:\\foo\\bar.txt", "file:///c:/foo/bar.txt"}, | 237 {L"C:\\foo\\bar.txt", "file:///c:/foo/bar.txt"}, | 
| 238 {L"\\\\foo\\bar.txt", "file:////foo\\bar.txt"}, | 238 {L"\\\\foo\\bar.txt", "file:////foo\\bar.txt"}, | 
| 239 {L"\\\\foo\\bar.txt", "file:/foo/bar.txt"}, | 239 {L"\\\\foo\\bar.txt", "file:/foo/bar.txt"}, | 
| 240 {L"\\\\foo\\bar.txt", "file://foo\\bar.txt"}, | 240 {L"\\\\foo\\bar.txt", "file://foo\\bar.txt"}, | 
| 241 {L"C:\\foo\\bar.txt", "file:\\\\\\c:/foo/bar.txt"}, | 241 {L"C:\\foo\\bar.txt", "file:\\\\\\c:/foo/bar.txt"}, | 
| 242 // %2f ('/') and %5c ('\\') are left alone by both GURL and | |
| 243 // FileURLToFilePath. | |
| 244 {L"C:\\foo%2f..%5cbar", "file:///C:\\foo%2f..%5cbar"}, | |
| 
eroman
2016/02/18 19:37:28
What are the unescaping rules for %2e   (dot) ?
 
mmenke
2016/02/18 20:30:22
Dots are unescaped in paths, since they have no ma
 
eroman
2016/02/18 21:17:22
But dots do have a magical meaning, which is no le
 | |
| 242 #elif defined(OS_POSIX) | 245 #elif defined(OS_POSIX) | 
| 243 {L"/c:/foo/bar.txt", "file:/c:/foo/bar.txt"}, | 246 {L"/c:/foo/bar.txt", "file:/c:/foo/bar.txt"}, | 
| 244 {L"/c:/foo/bar.txt", "file:///c:/foo/bar.txt"}, | 247 {L"/c:/foo/bar.txt", "file:///c:/foo/bar.txt"}, | 
| 245 {L"/foo/bar.txt", "file:/foo/bar.txt"}, | 248 {L"/foo/bar.txt", "file:/foo/bar.txt"}, | 
| 246 {L"/c:/foo/bar.txt", "file:\\\\\\c:/foo/bar.txt"}, | 249 {L"/c:/foo/bar.txt", "file:\\\\\\c:/foo/bar.txt"}, | 
| 247 {L"/foo/bar.txt", "file:foo/bar.txt"}, | 250 {L"/foo/bar.txt", "file:foo/bar.txt"}, | 
| 248 {L"/bar.txt", "file://foo/bar.txt"}, | 251 {L"/bar.txt", "file://foo/bar.txt"}, | 
| 249 {L"/foo/bar.txt", "file:///foo/bar.txt"}, | 252 {L"/foo/bar.txt", "file:///foo/bar.txt"}, | 
| 250 {L"/foo/bar.txt", "file:////foo/bar.txt"}, | 253 {L"/foo/bar.txt", "file:////foo/bar.txt"}, | 
| 251 {L"/foo/bar.txt", "file:////foo//bar.txt"}, | 254 {L"/foo/bar.txt", "file:////foo//bar.txt"}, | 
| 252 {L"/foo/bar.txt", "file:////foo///bar.txt"}, | 255 {L"/foo/bar.txt", "file:////foo///bar.txt"}, | 
| 253 {L"/foo/bar.txt", "file:////foo////bar.txt"}, | 256 {L"/foo/bar.txt", "file:////foo////bar.txt"}, | 
| 254 {L"/c:/foo/bar.txt", "file:\\\\\\c:/foo/bar.txt"}, | 257 {L"/c:/foo/bar.txt", "file:\\\\\\c:/foo/bar.txt"}, | 
| 255 {L"/c:/foo/bar.txt", "file:c:/foo/bar.txt"}, | 258 {L"/c:/foo/bar.txt", "file:c:/foo/bar.txt"}, | 
| 259 // %2f ('/') and %5c ('\\') are left alone by both GURL and | |
| 260 // FileURLToFilePath. | |
| 261 {L"/foo%2f..%5cbar", "file:///foo%2f..%5cbar"}, | |
| 256 // We get these wrong because GURL turns back slashes into forward | 262 // We get these wrong because GURL turns back slashes into forward | 
| 257 // slashes. | 263 // slashes. | 
| 258 // {L"/foo%5Cbar.txt", "file://foo\\bar.txt"}, | 264 // {L"/foo%5Cbar.txt", "file://foo\\bar.txt"}, | 
| 259 // {L"/c|/foo%5Cbar.txt", "file:c|/foo\\bar.txt"}, | 265 // {L"/c|/foo%5Cbar.txt", "file:c|/foo\\bar.txt"}, | 
| 260 // {L"/foo%5Cbar.txt", "file://foo\\bar.txt"}, | 266 // {L"/foo%5Cbar.txt", "file://foo\\bar.txt"}, | 
| 261 // {L"/foo%5Cbar.txt", "file:////foo\\bar.txt"}, | 267 // {L"/foo%5Cbar.txt", "file:////foo\\bar.txt"}, | 
| 262 // {L"/foo%5Cbar.txt", "file://foo\\bar.txt"}, | 268 // {L"/foo%5Cbar.txt", "file://foo\\bar.txt"}, | 
| 263 #endif | 269 #endif | 
| 264 }; | 270 }; | 
| 265 for (size_t i = 0; i < arraysize(url_cases); i++) { | 271 for (size_t i = 0; i < arraysize(url_cases); i++) { | 
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 778 L"\uc608\uc220 \uc608\uc220.jpg"}, | 784 L"\uc608\uc220 \uc608\uc220.jpg"}, | 
| 779 {// Invalid C-D. No filename from URL. Falls back to 'download'. | 785 {// Invalid C-D. No filename from URL. Falls back to 'download'. | 
| 780 __LINE__, | 786 __LINE__, | 
| 781 "http://www.google.com/path1/path2/", | 787 "http://www.google.com/path1/path2/", | 
| 782 "attachment; filename==?iso88591?Q?caf=E3?", | 788 "attachment; filename==?iso88591?Q?caf=E3?", | 
| 783 "", | 789 "", | 
| 784 "", | 790 "", | 
| 785 "image/jpeg", | 791 "image/jpeg", | 
| 786 L"download", | 792 L"download", | 
| 787 L"download" JPEG_EXT}, | 793 L"download" JPEG_EXT}, | 
| 794 {// Escaped slash, backslash, and leading periods in file name. The periods | |
| 795 // should be removed, both slashes replaced with dashes. | |
| 796 __LINE__, | |
| 797 "http://www.google.com/..%2f%5ctest.html", | |
| 798 "", | |
| 799 "", | |
| 800 "", | |
| 801 "", | |
| 802 L"", | |
| 803 L"--test.html"}, | |
| 788 }; | 804 }; | 
| 789 | 805 | 
| 790 // Tests filename generation. Once the correct filename is | 806 // Tests filename generation. Once the correct filename is | 
| 791 // selected, they should be passed through the validation steps and | 807 // selected, they should be passed through the validation steps and | 
| 792 // a correct extension should be added if necessary. | 808 // a correct extension should be added if necessary. | 
| 793 const GenerateFilenameCase generation_tests[] = { | 809 const GenerateFilenameCase generation_tests[] = { | 
| 794 // Dotfiles. Ensures preceeding period(s) stripped. | 810 // Dotfiles. Ensures preceeding period(s) stripped. | 
| 795 {__LINE__, "http://www.google.com/.test.html", "", "", "", "", L"", | 811 {__LINE__, "http://www.google.com/.test.html", "", "", "", "", L"", | 
| 796 L"test.html"}, | 812 L"test.html"}, | 
| 797 {__LINE__, "http://www.google.com/.test", "", "", "", "", L"", L"test"}, | 813 {__LINE__, "http://www.google.com/.test", "", "", "", "", L"", L"test"}, | 
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1067 } | 1083 } | 
| 1068 | 1084 | 
| 1069 for (size_t i = 0; i < arraysize(kUnsafePortableBasenamesForWindows); ++i) { | 1085 for (size_t i = 0; i < arraysize(kUnsafePortableBasenamesForWindows); ++i) { | 
| 1070 EXPECT_TRUE(IsReservedNameOnWindows( | 1086 EXPECT_TRUE(IsReservedNameOnWindows( | 
| 1071 base::FilePath(kUnsafePortableBasenamesForWindows[i]).value())) | 1087 base::FilePath(kUnsafePortableBasenamesForWindows[i]).value())) | 
| 1072 << kUnsafePortableBasenamesForWindows[i]; | 1088 << kUnsafePortableBasenamesForWindows[i]; | 
| 1073 } | 1089 } | 
| 1074 } | 1090 } | 
| 1075 | 1091 | 
| 1076 } // namespace net | 1092 } // namespace net | 
| OLD | NEW |