diff --git a/public/client.js b/public/client.js index 2cda6a53..8941fbe3 100644 --- a/public/client.js +++ b/public/client.js @@ -1,85 +1,114 @@ -$( document ).ready(function() { - let items = []; - let itemsRaw = []; - - $.getJSON('/api/books', function(data) { +// Regular expression to pick up HTML/XML tags, in case of any cross-site scripting attempts. +const tagRegex = /(?:\<\/?.+\>)/g; + +$(document).ready(function () { + let items = []; + let itemsRaw = []; + + $.getJSON("/api/books", function (data) { //let items = []; itemsRaw = data; - $.each(data, function(i, val) { - items.push('
  • ' + val.title + ' - ' + val.commentcount + ' comments
  • '); - return ( i !== 14 ); + $.each(data, function (i, val) { + items.push( + '
  • ' + + val.title.replace(tagRegex, "") + // If title in database has HTML tags, remove them. + " - " + + val.commentcount + + " comments
  • " + ); + return i !== 14; }); if (items.length >= 15) { - items.push('

    ...and '+ (data.length - 15)+' more!

    '); + items.push("

    ...and " + (data.length - 15) + " more!

    "); } - $('