Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/main/java/com/gitblit/utils/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public static String escapeForHtml(String inStr, boolean changeSpace) {
public static String escapeForHtml(String inStr, boolean changeSpace, int tabLength) {
StringBuilder retStr = new StringBuilder();
int i = 0;
int l = 0;

while (i < inStr.length()) {
if (inStr.charAt(i) == '&') {
retStr.append("&amp;");
Expand All @@ -106,12 +108,17 @@ public static String escapeForHtml(String inStr, boolean changeSpace, int tabLen
} else if (changeSpace && inStr.charAt(i) == ' ') {
retStr.append("&nbsp;");
} else if (changeSpace && inStr.charAt(i) == '\t') {
for (int j = 0; j < tabLength; j++) {
for (int j = 0; j < tabLength - l; j++) {
retStr.append("&nbsp;");
}
l = -1;
} else {
retStr.append(inStr.charAt(i));
}

l = (l + 1) % tabLength;
if (inStr.charAt(i) == '\n')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you wrap this if with curly braces?

l = 0;
i++;
}
return retStr.toString();
Expand Down