summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaud Fabre <fabre.arnaud@gmail.com>2013-06-29 22:41:27 +0200
committerArnaud Fabre <fabre.arnaud@gmail.com>2013-06-30 18:09:02 +0200
commit4faa7314a42ff780056e3f19327be887221dcedc (patch)
tree77bb118b2603e7c36fbb5a5b7ed9f9e8664f8b75
parentdc57f029208f3938c774dbc319d64c3190a8cdb6 (diff)
PrettyFormatter: Fix ArrayIndexOutOfBoundException with CRLF files.
Change I6d82ce322d401743a8de5ab8090b2adc43a909f5 added a workaround for a bug in prettify, by temporarily adding a space before each \n character. For files with CRLF line endings, this means replacing "\r\n" by "\r<space>\n", which prettify sees as two lines. This leads to a crash since Gerrit expects a consistent number of lines even after prettify. When Show Line Endings is active, the issue does not appear since \r are replaced with a specific markup, without any actual \r. Change-Id: I345e332225e449c6f26871476f1a07e67458da59
-rw-r--r--gerrit-prettify/src/main/java/com/google/gerrit/prettify/common/PrettyFormatter.java4
1 files changed, 2 insertions, 2 deletions
diff --git a/gerrit-prettify/src/main/java/com/google/gerrit/prettify/common/PrettyFormatter.java b/gerrit-prettify/src/main/java/com/google/gerrit/prettify/common/PrettyFormatter.java
index 511b056c86..d07a34da79 100644
--- a/gerrit-prettify/src/main/java/com/google/gerrit/prettify/common/PrettyFormatter.java
+++ b/gerrit-prettify/src/main/java/com/google/gerrit/prettify/common/PrettyFormatter.java
@@ -145,9 +145,9 @@ public abstract class PrettyFormatter implements SparseHtmlFile {
// Drop any '\r' to avoid this problem.
html = html.replace("\r</span>\n", "</span>\n");
- html = html.replace("\n", " \n");
+ html = html.replaceAll("(\r)?\n", " $1\n");
html = prettify(html, getFileType());
- html = html.replace(" \n", "\n");
+ html = html.replaceAll(" (\r)?\n", "$1\n");
} else {
html = expandTabs(html);
}