papa parse - unescape imported data
papa parse - unescape imported data

I am using papa parse in my project to import a csv file. I am having an issue though because values are coming in escaped, so an ampersand is coming in as & I see that javascript has an 'unescape()' function,but not sure how to use it with the papa parse function:
var uploadEditor = new $.fn.dataTable.Editor({
fields: [{
label: 'CSV file:',
name: 'csv',
type: 'upload',
ajax: function (files) {
// Ajax override of the upload so we can handle the file locally. Here we use Papa
// to parse the CSV.
Papa.parse(files[0], {
header: true,
//change the 4th column header to 'Email'
beforeFirstChunk: function (chunk) {
var index = chunk.match(/\r\n|\r|\n/).index;
var headings = chunk.substr(0, index).split(',');
headings[3] = 'Email';
return headings.join() + chunk.substr(index);
},
skipEmptyLines: true,
delimiter: ",",
complete: function (results) {
if (results.errors.length) {
console.log(results);
uploadEditor.field('csv').error('CSV parsing error: ' + results.errors[0].message);
}
else {
uploadEditor.close();
selectColumns(editor, results.data, results.meta.fields);
}
}
});
}
}]
});
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You could loop over the
results.data
array and decode each in turn there.PapaParse might have something that will help you do this itself, but I don't know I'm afraid, You'd need to ask in their support channels.
Allan
actually, it seems that papa parse is not where the issue is? On dataTable submit I try this:
and console.log(unescape(csv[j][mapped])); is showing the data correctly. Is it something to do with multiset() or with the editor, or the way I have my controller (MVC project) written?
actually, even if I leave off the unescape() it appears correctly in the console log.
and just to confirm, I am looking at the raw csv file and the ampersands are showing correctly. It appears that something is going on when it sends it to SQL
Are you using .NET on the server-side? (I feel I should remember from your previous posts, but I can't!). If so, use
.Xss(false)
on theField
elements which will disable the Microsoft anti-XSS library. It sounds like you might be running into an issue with it being overly aggressive in its encoding.Allan
yes!! that was it. thank you so much!