Index: net/base/filename_util.cc |
diff --git a/net/base/filename_util.cc b/net/base/filename_util.cc |
index c9d5fe4b5f2652bb7ab47c57d3cf80fe7ab95b9e..7d60c39683d5eddae48cbf312d582cf89aafb045 100644 |
--- a/net/base/filename_util.cc |
+++ b/net/base/filename_util.cc |
@@ -63,6 +63,39 @@ GURL FilePathToFileURL(const base::FilePath& path) { |
return GURL(url_string); |
} |
+GURL FilePathToFileURLNoCWD(const base::FilePath& path) { |
+ // Produce a URL like "file:///C:/foo" for a regular file, or |
+ // "file://///server/path" for UNC. The URL canonicalizer will fix up the |
+ // latter case to be the canonical UNC form: "file://server/path" |
+ base::FilePath::StringType url_string(kFileURLPrefix); |
+ url_string.append(path.value()); |
+ // Do replacement of some characters. Since we assume the input is a |
+ // literal filename, anything the URL parser might consider special should |
+ // be escaped here. |
+ |
+ // must be the first substitution since others will introduce percents as the |
+ // escape character |
+ ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL("%"), |
+ FILE_PATH_LITERAL("%25")); |
+ |
+ // semicolon is supposed to be some kind of separator according to RFC 2396 |
+ ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL(";"), |
+ FILE_PATH_LITERAL("%3B")); |
+ |
+ ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL("#"), |
+ FILE_PATH_LITERAL("%23")); |
+ |
+ ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL("?"), |
+ FILE_PATH_LITERAL("%3F")); |
+ |
+#if defined(OS_POSIX) |
+ ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL("\\"), |
+ FILE_PATH_LITERAL("%5C")); |
+#endif |
davidben
2015/04/14 16:26:22
This is too much code to be duplicated. Move thing
|
+ |
+ return GURL(url_string); |
+} |
+ |
bool FileURLToFilePath(const GURL& url, base::FilePath* file_path) { |
*file_path = base::FilePath(); |
base::FilePath::StringType& file_path_str = |