cleanTitle() to escape all common chars

This commit is contained in:
teddit 2020-12-02 17:08:55 +01:00
parent 6f1b88a4c7
commit afb800d585
1 changed files with 21 additions and 2 deletions

View File

@ -95,6 +95,25 @@ meta(name="viewport", content="width=device-width, initial-scale=1.0")
return new Date(time * 1000).toISOString().substr(14,5)
}
function cleanTitle(title) {
return title.replace(/&/g, '&')
function cleanTitle(s) {
if(s) {
var re = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
var unescaped = {
'&': '&',
'&': '&',
'&lt;': '<',
'&#60;': '<',
'&gt;': '>',
'&#62;': '>',
'&apos;': "'",
'&#39;': "'",
'&quot;': '"',
'&#34;': '"'
}
return s.replace(re, (m) => {
return unescaped[m]
})
} else {
return ''
}
}