refactor: Use escape-goat instead of escape-html and unescape-html

Signed-off-by: Richie Bendall <richiebendall@gmail.com>
This commit is contained in:
Richie Bendall 2020-03-18 17:58:08 +13:00
parent 5a2c74357f
commit 4b38621ab8
No known key found for this signature in database
GPG key ID: 1C6A99DFA9D306FC
3 changed files with 9 additions and 11 deletions

View file

@ -29,7 +29,7 @@
"any-size": "^1.0.0",
"btoa": "^1.2.1",
"ejs": "^3.0.1",
"escape-html": "^1.0.3",
"escape-goat": "^3.0.0",
"express": "^4.17.1",
"express-minify": "^1.0.0",
"fs-extra": "^8.1.0",
@ -39,7 +39,6 @@
"postcss-preset-env": "^6.7.0",
"serve-favicon": "^2.5.0",
"temp-dir": "^2.0.0",
"unescape-html": "^1.1.0",
"yn": "^4.0.0"
},
"devDependencies": {

View file

@ -1,8 +1,7 @@
const md5 = require('md5')
const path = require('path')
const escapeTags = require('escape-html')
const unescapeTags = require('unescape-html')
const stripTags = require('html-text')
const { htmlEscape, htmlUnescape } = require('escape-goat')
const stripHtml = require('html-text')
const is = require('@sindresorhus/is')
function getCopyrightHTML (user, plain) {
@ -12,17 +11,17 @@ function getCopyrightHTML (user, plain) {
? user
: plain
? user.name || user.copyright
: escapeTags(user.name || user.copyright)
: htmlEscape(user.name || user.copyright)
if (user.url) {
html = `<a href="${stripTags(user.url)}">${name}</a>`
html = `<a href="${stripHtml(user.url)}">${name}</a>`
} else {
html = name
}
if (user.email) {
html += ` &lt;<a href="mailto:${stripTags(user.email)}">${
plain ? user.email : escapeTags(user.email)
html += ` &lt;<a href="mailto:${stripHtml(user.email)}">${
plain ? user.email : htmlEscape(user.email)
}</a>&gt;`
}
@ -41,7 +40,7 @@ module.exports = (req, res) => {
} else if (is.array(user.copyright) && user.copyright.every(val => is.string(val))) {
// Supports: ['Remy Sharp', 'Richie Bendall']
name = user.copyright
.map(v => (options.format !== 'html' ? v : escapeTags(v)))
.map(v => (options.format !== 'html' ? v : htmlEscape(v)))
.join(', ')
} else {
name = user.copyright.map(getCopyrightHTML).join(', ')
@ -84,7 +83,7 @@ module.exports = (req, res) => {
res
.set('Content-Type', 'text/plain; charset=UTF-8')
.send(unescapeTags(stripTags(plain)).trim())
.send(htmlUnescape(stripHtml(plain)).trim())
return
}

BIN
yarn.lock

Binary file not shown.