Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: extensions/browser/file_highlighter.cc

Issue 23875013: Handle invalid input for SourceHighlighter, Don't Allow Relative Paths in ErrorHandler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | extensions/browser/file_highlighter_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/file_highlighter.cc
diff --git a/extensions/browser/file_highlighter.cc b/extensions/browser/file_highlighter.cc
index d3edeca42cf7bb0eed41ef2f95df899de1700816..d8acdb494bfe09c221c290d2531178865088ccc0 100644
--- a/extensions/browser/file_highlighter.cc
+++ b/extensions/browser/file_highlighter.cc
@@ -203,8 +203,21 @@ SourceHighlighter::~SourceHighlighter() {
}
void SourceHighlighter::Parse(size_t line_number) {
- for (size_t i = 1; i < line_number; ++i)
- start_ = contents_.find('\n', start_) + 1;
+ // If line 0 is requested, highlight nothing.
+ if (line_number == 0) {
+ start_ = contents_.size();
+ return;
+ }
+
+ for (size_t i = 1; i < line_number; ++i) {
+ start_ = contents_.find('\n', start_);
+ // If we find the end of the string, then break. Otherwise, increment start
+ // to be at the first character of the new line.
Finnur 2013/09/09 18:19:30 One doesn't gain much information from this commen
Devlin 2013/09/09 18:26:16 Removed.
+ if (start_ == std::string::npos)
+ break;
+ start_ += 1;
+ }
+
end_ = contents_.find('\n', start_);
// If we went off the end of the string (i.e., the line number was invalid),
« no previous file with comments | « no previous file | extensions/browser/file_highlighter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698