Block HTML content in posts content

This commit is contained in:
Pierre HUBERT 2021-03-08 17:19:26 +01:00
parent 30353c5277
commit 35d1e6a8b1
3 changed files with 33 additions and 2 deletions

View File

@ -106,7 +106,7 @@ function ApplyPosts(){
appendTo: cardContent, appendTo: cardContent,
type: "div", type: "div",
class: "post-content", class: "post-content",
innerHTML: post.content innerHTML: removeHtmlTags(post.content)
}); });

View File

@ -20,7 +20,7 @@ function RefreshTabsVisibility(){
var hash = location.href.toString().split("#")[1]; var hash = location.href.toString().split("#")[1];
if(!hash) if(!hash)
return; hash = "home";
document.querySelectorAll(".category").forEach(el => { document.querySelectorAll(".category").forEach(el => {

View File

@ -240,4 +240,35 @@ function userID() {
*/ */
function fileSizeToHuman(size) { function fileSizeToHuman(size) {
return Math.round(size/(1000*1000)*1000)/1000 + "MB"; return Math.round(size/(1000*1000)*1000)/1000 + "MB";
}
/**
* Remove HTML carachters : < and >
*
* @param {String} input The string to change
* @return {String} The updated string
*/
function removeHtmlTags(input){
//Check if input string is empty
if(input == null || typeof input !== "string")
return "";
//Prepare update
var output = input;
//Replace opening braces
while(output.includes("<")){
//Replace an occurence
output = output.replace("<", "&lt;");
}
//Replace closing braces
while(output.includes(">")){
//Replace an occurence
output = output.replace(">", "&gt;");
}
//Return result
return output;
} }