| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "modules/filesystem/DOMFilePath.h" | 32 #include "modules/filesystem/DOMFilePath.h" |
| 33 | 33 |
| 34 #include "wtf/Vector.h" | 34 #include "wtf/Vector.h" |
| 35 #include "wtf/text/CString.h" | 35 #include "wtf/text/CString.h" |
| 36 #include "wtf/text/StringBuilder.h" |
| 36 | 37 |
| 37 namespace WebCore { | 38 namespace WebCore { |
| 38 | 39 |
| 39 const char DOMFilePath::separator = '/'; | 40 const char DOMFilePath::separator = '/'; |
| 40 const char DOMFilePath::root[] = "/"; | 41 const char DOMFilePath::root[] = "/"; |
| 41 | 42 |
| 42 String DOMFilePath::append(const String& base, const String& components) | 43 String DOMFilePath::append(const String& base, const String& components) |
| 43 { | 44 { |
| 44 return ensureDirectoryPath(base) + components; | 45 return ensureDirectoryPath(base) + components; |
| 45 } | 46 } |
| 46 | 47 |
| 47 String DOMFilePath::ensureDirectoryPath(const String& path) | 48 String DOMFilePath::ensureDirectoryPath(const String& path) |
| 48 { | 49 { |
| 49 if (!DOMFilePath::endsWithSeparator(path)) { | 50 if (!DOMFilePath::endsWithSeparator(path)) |
| 50 String newPath = path; | 51 return path + DOMFilePath::separator; |
| 51 newPath.append(DOMFilePath::separator); | |
| 52 return newPath; | |
| 53 } | |
| 54 return path; | 52 return path; |
| 55 } | 53 } |
| 56 | 54 |
| 57 String DOMFilePath::getName(const String& path) | 55 String DOMFilePath::getName(const String& path) |
| 58 { | 56 { |
| 59 int index = path.reverseFind(DOMFilePath::separator); | 57 int index = path.reverseFind(DOMFilePath::separator); |
| 60 if (index != -1) | 58 if (index != -1) |
| 61 return path.substring(index + 1); | 59 return path.substring(index + 1); |
| 62 return path; | 60 return path; |
| 63 } | 61 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 continue; | 94 continue; |
| 97 if (components[i] == "..") { | 95 if (components[i] == "..") { |
| 98 if (canonicalized.size() > 0) | 96 if (canonicalized.size() > 0) |
| 99 canonicalized.removeLast(); | 97 canonicalized.removeLast(); |
| 100 continue; | 98 continue; |
| 101 } | 99 } |
| 102 canonicalized.append(components[i]); | 100 canonicalized.append(components[i]); |
| 103 } | 101 } |
| 104 if (canonicalized.isEmpty()) | 102 if (canonicalized.isEmpty()) |
| 105 return DOMFilePath::root; | 103 return DOMFilePath::root; |
| 106 String result; | 104 StringBuilder result; |
| 107 for (size_t i = 0; i < canonicalized.size(); ++i) { | 105 for (size_t i = 0; i < canonicalized.size(); ++i) { |
| 108 result.append(DOMFilePath::separator); | 106 result.append(DOMFilePath::separator); |
| 109 result.append(canonicalized[i]); | 107 result.append(canonicalized[i]); |
| 110 } | 108 } |
| 111 return result; | 109 return result.toString(); |
| 112 } | 110 } |
| 113 | 111 |
| 114 bool DOMFilePath::isValidPath(const String& path) | 112 bool DOMFilePath::isValidPath(const String& path) |
| 115 { | 113 { |
| 116 if (path.isEmpty() || path == DOMFilePath::root) | 114 if (path.isEmpty() || path == DOMFilePath::root) |
| 117 return true; | 115 return true; |
| 118 | 116 |
| 119 // Embedded NULs are not allowed. | 117 // Embedded NULs are not allowed. |
| 120 if (path.find(static_cast<UChar>(0)) != WTF::kNotFound) | 118 if (path.find(static_cast<UChar>(0)) != WTF::kNotFound) |
| 121 return false; | 119 return false; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 140 { | 138 { |
| 141 if (name.isEmpty()) | 139 if (name.isEmpty()) |
| 142 return true; | 140 return true; |
| 143 // '/' is not allowed in name. | 141 // '/' is not allowed in name. |
| 144 if (name.contains('/')) | 142 if (name.contains('/')) |
| 145 return false; | 143 return false; |
| 146 return isValidPath(name); | 144 return isValidPath(name); |
| 147 } | 145 } |
| 148 | 146 |
| 149 } // namespace WebCore | 147 } // namespace WebCore |
| OLD | NEW |