mirror of
https://github.com/samsonjs/mit-license.git
synced 2026-04-27 15:07:42 +00:00
refactor: Use escape-goat instead of escape-html and unescape-html
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
This commit is contained in:
parent
5a2c74357f
commit
4b38621ab8
3 changed files with 9 additions and 11 deletions
|
|
@ -29,7 +29,7 @@
|
||||||
"any-size": "^1.0.0",
|
"any-size": "^1.0.0",
|
||||||
"btoa": "^1.2.1",
|
"btoa": "^1.2.1",
|
||||||
"ejs": "^3.0.1",
|
"ejs": "^3.0.1",
|
||||||
"escape-html": "^1.0.3",
|
"escape-goat": "^3.0.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"express-minify": "^1.0.0",
|
"express-minify": "^1.0.0",
|
||||||
"fs-extra": "^8.1.0",
|
"fs-extra": "^8.1.0",
|
||||||
|
|
@ -39,7 +39,6 @@
|
||||||
"postcss-preset-env": "^6.7.0",
|
"postcss-preset-env": "^6.7.0",
|
||||||
"serve-favicon": "^2.5.0",
|
"serve-favicon": "^2.5.0",
|
||||||
"temp-dir": "^2.0.0",
|
"temp-dir": "^2.0.0",
|
||||||
"unescape-html": "^1.1.0",
|
|
||||||
"yn": "^4.0.0"
|
"yn": "^4.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
const md5 = require('md5')
|
const md5 = require('md5')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const escapeTags = require('escape-html')
|
const { htmlEscape, htmlUnescape } = require('escape-goat')
|
||||||
const unescapeTags = require('unescape-html')
|
const stripHtml = require('html-text')
|
||||||
const stripTags = require('html-text')
|
|
||||||
const is = require('@sindresorhus/is')
|
const is = require('@sindresorhus/is')
|
||||||
|
|
||||||
function getCopyrightHTML (user, plain) {
|
function getCopyrightHTML (user, plain) {
|
||||||
|
|
@ -12,17 +11,17 @@ function getCopyrightHTML (user, plain) {
|
||||||
? user
|
? user
|
||||||
: plain
|
: plain
|
||||||
? user.name || user.copyright
|
? user.name || user.copyright
|
||||||
: escapeTags(user.name || user.copyright)
|
: htmlEscape(user.name || user.copyright)
|
||||||
|
|
||||||
if (user.url) {
|
if (user.url) {
|
||||||
html = `<a href="${stripTags(user.url)}">${name}</a>`
|
html = `<a href="${stripHtml(user.url)}">${name}</a>`
|
||||||
} else {
|
} else {
|
||||||
html = name
|
html = name
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.email) {
|
if (user.email) {
|
||||||
html += ` <<a href="mailto:${stripTags(user.email)}">${
|
html += ` <<a href="mailto:${stripHtml(user.email)}">${
|
||||||
plain ? user.email : escapeTags(user.email)
|
plain ? user.email : htmlEscape(user.email)
|
||||||
}</a>>`
|
}</a>>`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,7 +40,7 @@ module.exports = (req, res) => {
|
||||||
} else if (is.array(user.copyright) && user.copyright.every(val => is.string(val))) {
|
} else if (is.array(user.copyright) && user.copyright.every(val => is.string(val))) {
|
||||||
// Supports: ['Remy Sharp', 'Richie Bendall']
|
// Supports: ['Remy Sharp', 'Richie Bendall']
|
||||||
name = user.copyright
|
name = user.copyright
|
||||||
.map(v => (options.format !== 'html' ? v : escapeTags(v)))
|
.map(v => (options.format !== 'html' ? v : htmlEscape(v)))
|
||||||
.join(', ')
|
.join(', ')
|
||||||
} else {
|
} else {
|
||||||
name = user.copyright.map(getCopyrightHTML).join(', ')
|
name = user.copyright.map(getCopyrightHTML).join(', ')
|
||||||
|
|
@ -84,7 +83,7 @@ module.exports = (req, res) => {
|
||||||
|
|
||||||
res
|
res
|
||||||
.set('Content-Type', 'text/plain; charset=UTF-8')
|
.set('Content-Type', 'text/plain; charset=UTF-8')
|
||||||
.send(unescapeTags(stripTags(plain)).trim())
|
.send(htmlUnescape(stripHtml(plain)).trim())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
BIN
yarn.lock
BIN
yarn.lock
Binary file not shown.
Loading…
Reference in a new issue