Commit c4ae40dd authored by rchlodnicki's avatar rchlodnicki Committed by Commit bot

Make sure there is no crash on parsing empty manifest

Changes match the logic in SourceHighlighter in the same file and will
result in UI showing message akin to 'No source file available'. This is fine
as already the same happens for other source files in bundled extensions.

BUG=627896

Review-Url: https://codereview.chromium.org/2245143004
Cr-Commit-Position: refs/heads/master@{#412556}
parent ba735f09
...@@ -113,8 +113,10 @@ ManifestHighlighter::ManifestHighlighter(const std::string& manifest, ...@@ -113,8 +113,10 @@ ManifestHighlighter::ManifestHighlighter(const std::string& manifest,
const std::string& key, const std::string& key,
const std::string& specific) const std::string& specific)
: FileHighlighter(manifest) { : FileHighlighter(manifest) {
start_ = contents_.find('{') + 1; start_ = contents_.find('{');
start_ = start_ == std::string::npos ? contents_.size() : start_ + 1;
end_ = contents_.rfind('}'); end_ = contents_.rfind('}');
end_ = end_ == std::string::npos ? contents_.size() : end_;
Parse(key, specific); Parse(key, specific);
} }
...@@ -125,11 +127,11 @@ ManifestHighlighter::~ManifestHighlighter() { ...@@ -125,11 +127,11 @@ ManifestHighlighter::~ManifestHighlighter() {
void ManifestHighlighter::Parse(const std::string& key, void ManifestHighlighter::Parse(const std::string& key,
const std::string& specific) { const std::string& specific) {
// First, try to find the bounds of the full key. // First, try to find the bounds of the full key.
if (FindBounds(key, true) /* enforce at top level */ ) { if (FindBounds(key, true) /* enforce at top level */) {
// If we succeed, and we have a specific location, find the bounds of the // If we succeed, and we have a specific location, find the bounds of the
// specific. // specific.
if (!specific.empty()) if (!specific.empty())
FindBounds(specific, false /* don't enforce at top level */ ); FindBounds(specific, false /* don't enforce at top level */);
// We may have found trailing whitespace. Don't use base::TrimWhitespace, // We may have found trailing whitespace. Don't use base::TrimWhitespace,
// because we want to keep any whitespace we find - just not highlight it. // because we want to keep any whitespace we find - just not highlight it.
......
...@@ -93,6 +93,11 @@ TEST(ManifestHighlighterUnitTest, ManifestHighlighterUnitTest) { ...@@ -93,6 +93,11 @@ TEST(ManifestHighlighterUnitTest, ManifestHighlighterUnitTest) {
ManifestHighlighter international_feature( ManifestHighlighter international_feature(
kManifest, "international_key", std::string()); kManifest, "international_key", std::string());
EXPECT_EQ(kInternationalFeature, international_feature.GetFeature()); EXPECT_EQ(kInternationalFeature, international_feature.GetFeature());
// Empty manifest. Check that there is no crash.
const char kEmptyManifest[] = "";
ManifestHighlighter no_feature(kEmptyManifest, std::string(), std::string());
EXPECT_EQ(std::string(), no_feature.GetFeature());
} }
TEST(SouceHighlighterUnitTest, SourceHighlighterUnitTest) { TEST(SouceHighlighterUnitTest, SourceHighlighterUnitTest) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment