Skip to content

Commit

Permalink
Merge pull request #716 from ashitsalesforce/master
Browse files Browse the repository at this point in the history
Fix for the issue reported in PR #715
  • Loading branch information
ashitsalesforce authored Jul 5, 2023
2 parents fba0d34 + 1d6bca2 commit 8459a2e
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.*;

import com.salesforce.dataloader.model.Row;
import com.salesforce.dataloader.util.AppUtil;
import com.salesforce.dataloader.util.DAORowUtil;

import org.apache.commons.beanutils.*;
Expand Down Expand Up @@ -317,17 +318,31 @@ private static String escapeHTMLChars(String input) {
if (input == null) {
return null;
}
input = StringEscapeUtils.escapeHtml4(input);

// space characters need further handling
StringBuffer htmlFormattedStr = new StringBuffer("");
for (int i = 0, len = input.length(); i < len; i++) {
char c = input.charAt(i);
int cval = c;
if (Character.isWhitespace(c) || cval == NONBREAKING_SPACE_ASCII_VAL) {
htmlFormattedStr.append("&nbsp;");
char nextChar = 0;
if (i+1 < input.length()) {
nextChar = input.charAt(i+1);
}
char prevChar = 0;
if (i > 0) {
prevChar = input.charAt(i-1);
}

boolean isCharWhitespace = Character.isWhitespace(c) || cval == NONBREAKING_SPACE_ASCII_VAL;
boolean isNextCharWhitespace = Character.isWhitespace(nextChar) || nextChar == NONBREAKING_SPACE_ASCII_VAL;
boolean isPrevCharWhitespace = Character.isWhitespace(prevChar) || prevChar == NONBREAKING_SPACE_ASCII_VAL;
//only occurrences of multiple w
if (isCharWhitespace) {
if (isNextCharWhitespace || isPrevCharWhitespace) {
htmlFormattedStr.append("&nbsp;");
} else {
htmlFormattedStr.append(c);
}
} else {
htmlFormattedStr.append(c);
htmlFormattedStr.append(StringEscapeUtils.escapeHtml4(Character.toString(c)));
}
}
return htmlFormattedStr.toString();
Expand Down

0 comments on commit 8459a2e

Please sign in to comment.