Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for the issue reported in PR #715 #716

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Changes from all commits
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
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