Skip to content

Commit

Permalink
Use jQuery text() method to safely render table rows with HTML escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
sponomarev committed Apr 20, 2018
1 parent 6076437 commit 77ec839
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions js/csv_to_html_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ CsvToHtmlTable = {
var $tableBody = $("<tbody></tbody>");

for (var rowIdx = 1; rowIdx < csvData.length; rowIdx++) {
var row_html = "<tr>";
var $tableBodyRow = $("<tr></tr>");
for (var colIdx = 0; colIdx < csvData[rowIdx].length; colIdx++) {
var $tableBodyRowTd = $("<td></td>");
var cellTemplateFunc = customTemplates[colIdx];
if (cellTemplateFunc) {
row_html += "<td>" + cellTemplateFunc(csvData[rowIdx][colIdx]) + "</td>";
$tableBodyRowTd.html(cellTemplateFunc(csvData[rowIdx][colIdx]));
} else {
row_html += "<td>" + csvData[rowIdx][colIdx] + "</td>";
$tableBodyRowTd.text(csvData[rowIdx][colIdx]);
}
$tableBodyRow.append($tableBodyRowTd);
$tableBody.append($tableBodyRow);
}

row_html += "</tr>";
$tableBody.append(row_html);
}
$table.append($tableBody);

Expand Down

0 comments on commit 77ec839

Please sign in to comment.