Index: extensions/browser/content_verifier.cc |
diff --git a/extensions/browser/content_verifier.cc b/extensions/browser/content_verifier.cc |
index eaafe8f403bb2175063aa12d9ab6fe82cbceca63..3c778929e031266086fd9e60eec329b9efd07b87 100644 |
--- a/extensions/browser/content_verifier.cc |
+++ b/extensions/browser/content_verifier.cc |
@@ -24,6 +24,31 @@ namespace { |
ContentVerifier::TestObserver* g_test_observer = NULL; |
+// This function converts paths like "//foo/bar", "./foo/bar", and |
+// "/foo/bar" to "foo/bar". It also converts path separators to "/". |
+base::FilePath NormalizeRelativePath(const base::FilePath& path) { |
+ if (path.ReferencesParent()) |
+ return base::FilePath(); |
+ |
+ std::vector<base::FilePath::StringType> parts; |
+ path.GetComponents(&parts); |
+ if (parts.empty()) |
+ return base::FilePath(); |
+ |
+ // Remove the first component if it is '.' or '/' or '//'. |
+ const base::FilePath::StringType separators( |
+ base::FilePath::kSeparators, base::FilePath::kSeparatorsLength); |
+ if (!parts[0].empty() && |
+ (parts[0] == base::FilePath::kCurrentDirectory || |
+ parts[0].find_first_not_of(separators) == std::string::npos)) |
+ parts.erase(parts.begin()); |
+ |
+ // Note that elsewhere we always normalize path separators to '/' so this |
+ // should work for all platforms. |
+ return base::FilePath( |
+ base::JoinString(parts, base::FilePath::StringType(1, '/'))); |
+} |
+ |
} // namespace |
// static |
@@ -73,8 +98,10 @@ ContentVerifyJob* ContentVerifier::CreateJobFor( |
if (!data) |
return NULL; |
+ base::FilePath normalized_path = NormalizeRelativePath(relative_path); |
+ |
std::set<base::FilePath> paths; |
- paths.insert(relative_path); |
+ paths.insert(normalized_path); |
if (!ShouldVerifyAnyPaths(extension_id, extension_root, paths)) |
return NULL; |
@@ -82,7 +109,7 @@ ContentVerifyJob* ContentVerifier::CreateJobFor( |
// a cache of ContentHashReader's that we hold onto past the end of each job. |
return new ContentVerifyJob( |
new ContentHashReader(extension_id, data->version, extension_root, |
- relative_path, delegate_->GetPublicKey()), |
+ normalized_path, delegate_->GetPublicKey()), |
base::Bind(&ContentVerifier::VerifyFailed, this, extension_id)); |
} |
@@ -116,29 +143,6 @@ void ContentVerifier::VerifyFailed(const std::string& extension_id, |
} |
} |
-static base::FilePath MakeImagePathRelative(const base::FilePath& path) { |
- if (path.ReferencesParent()) |
- return base::FilePath(); |
- |
- std::vector<base::FilePath::StringType> parts; |
- path.GetComponents(&parts); |
- if (parts.empty()) |
- return base::FilePath(); |
- |
- // Remove the first component if it is '.' or '/' or '//'. |
- const base::FilePath::StringType separators( |
- base::FilePath::kSeparators, base::FilePath::kSeparatorsLength); |
- if (!parts[0].empty() && |
- (parts[0] == base::FilePath::kCurrentDirectory || |
- parts[0].find_first_not_of(separators) == std::string::npos)) |
- parts.erase(parts.begin()); |
- |
- // Note that elsewhere we always normalize path separators to '/' so this |
- // should work for all platforms. |
- return base::FilePath( |
- base::JoinString(parts, base::FilePath::StringType(1, '/'))); |
-} |
- |
void ContentVerifier::OnExtensionLoaded( |
content::BrowserContext* browser_context, |
const Extension* extension) { |
@@ -156,7 +160,7 @@ void ContentVerifier::OnExtensionLoaded( |
scoped_ptr<std::set<base::FilePath>> image_paths( |
new std::set<base::FilePath>); |
for (const auto& path : original_image_paths) { |
- image_paths->insert(MakeImagePathRelative(path)); |
+ image_paths->insert(NormalizeRelativePath(path)); |
} |
scoped_ptr<ContentVerifierIOData::ExtensionData> data( |