Skip to content

Commit

Permalink
Merge pull request #8343 from IQSS/8193-guestbook-csv-bug
Browse files Browse the repository at this point in the history
#8193 strip commas from email response
  • Loading branch information
kcondon authored Jan 25, 2022
2 parents e739b50 + 393fae6 commit 0ea1f04
Showing 1 changed file with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
import edu.harvard.iq.dataverse.authorization.users.User;
import edu.harvard.iq.dataverse.externaltools.ExternalTool;
import edu.harvard.iq.dataverse.util.BundleUtil;
import edu.harvard.iq.dataverse.util.StringUtil;
import java.io.IOException;
import java.io.OutputStream;
Expand All @@ -25,9 +24,6 @@
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.inject.Named;
import javax.persistence.EntityManager;
Expand Down Expand Up @@ -185,14 +181,14 @@ public StringBuilder convertGuestbookResponsesToCSV ( Map<Integer, Object> custo
// string fields, or the structure of the file will be broken. -- L.A.

// Guestbook name:
sb.append(((String)result[1]).replace(',', ' '));
sb.append(StringEscapeUtils.escapeCsv((String)result[1]));
sb.append(SEPARATOR);


// Dataset name:
Integer datasetId = (Integer) result[2];
String datasetTitle = datasetTitles.get(datasetId);
sb.append(datasetTitle == null ? "" : datasetTitle.replace(',', ' '));
sb.append(datasetTitle == null ? "" : StringEscapeUtils.escapeCsv(datasetTitle));
sb.append(SEPARATOR);

// Dataset persistent identifier:
Expand All @@ -211,7 +207,7 @@ public StringBuilder convertGuestbookResponsesToCSV ( Map<Integer, Object> custo
sb.append(SEPARATOR);

// file name:
sb.append(((String)result[5]).replace(',', ' '));
sb.append(StringEscapeUtils.escapeCsv((String)result[5]));
sb.append(SEPARATOR);

// file id (numeric):
Expand All @@ -224,19 +220,19 @@ public StringBuilder convertGuestbookResponsesToCSV ( Map<Integer, Object> custo
sb.append(SEPARATOR);

// name supplied in the guestbook response:
sb.append(result[7] == null ? "" : ((String)result[7]).replace(',', ' '));
sb.append(result[7] == null ? "" : StringEscapeUtils.escapeCsv((String)result[7]));
sb.append(SEPARATOR);

// email:
sb.append(result[8] == null ? "" : result[8]);
sb.append(result[8] == null ? "" : StringEscapeUtils.escapeCsv((String)result[8]));
sb.append(SEPARATOR);

// institution:
sb.append(result[9] == null ? "" : ((String)result[9]).replace(',', ' '));
sb.append(result[9] == null ? "" : StringEscapeUtils.escapeCsv((String)result[9]));
sb.append(SEPARATOR);

// position:
sb.append(result[10] == null ? "" : ((String)result[10]).replace(',', ' '));
sb.append(result[10] == null ? "" : StringEscapeUtils.escapeCsv((String)result[10]));

// Finally, custom questions and answers, if present:

Expand Down Expand Up @@ -401,8 +397,7 @@ private Map<Integer, Object> selectCustomQuestionAnswers(Long dataverseId, Long
if (asString) {
// as combined strings of comma-separated question and answer values
//assuming the strings are only being created for writing out to csv which seems to be the case
String qa = SEPARATOR + StringEscapeUtils.escapeCsv((String)response[0]) + SEPARATOR + (response[1] == null ? "" : StringEscapeUtils.escapeCsv((String)response[1]));

String qa = SEPARATOR + StringEscapeUtils.escapeCsv((String)response[0]) + SEPARATOR + (response[1] == null ? "" : StringEscapeUtils.escapeCsv((String)response[1]));
if (ret.containsKey(responseId)) {
ret.put(responseId, ret.get(responseId) + qa);
} else {
Expand Down

0 comments on commit 0ea1f04

Please sign in to comment.