mirror of
https://github.com/dzeiocom/libs.git
synced 2025-04-23 03:12:12 +00:00
Escapes all texts
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
parent
0f2cb1d58b
commit
4805ee6bcc
@ -36,12 +36,7 @@ export default class Sitemap {
|
|||||||
}) {
|
}) {
|
||||||
let entryString = '<url>'
|
let entryString = '<url>'
|
||||||
|
|
||||||
const url = `${this.domain}${path}`
|
const url = this.fixText(`${this.domain}${path}`)
|
||||||
.replace(/&/g, '&')
|
|
||||||
.replace(/'/g, ''')
|
|
||||||
.replace(/"/g, '"')
|
|
||||||
.replace(/>/g, '>')
|
|
||||||
.replace(/</g, '<')
|
|
||||||
|
|
||||||
entryString += `<loc>${url}</loc>`
|
entryString += `<loc>${url}</loc>`
|
||||||
if (options) {
|
if (options) {
|
||||||
@ -53,7 +48,7 @@ export default class Sitemap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options.lastmod) {
|
if (options.lastmod) {
|
||||||
entryString += `<lastmod>${options.lastmod.toISOString()}</lastmod>`
|
entryString += `<lastmod>${this.fixText(options.lastmod.toISOString())}</lastmod>`
|
||||||
}
|
}
|
||||||
if (options.priority) {
|
if (options.priority) {
|
||||||
if (options.priority <= 1 && options.priority >= 0 && options.priority.toString().length <= 3) {
|
if (options.priority <= 1 && options.priority >= 0 && options.priority.toString().length <= 3) {
|
||||||
@ -72,11 +67,11 @@ export default class Sitemap {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
entryString += '<image:image>'
|
entryString += '<image:image>'
|
||||||
entryString += `<image:loc>${image.location.startsWith('/') ? `${this.domain}${image.location}` : image.location}</image:loc>`
|
entryString += `<image:loc>${this.fixText(image.location.startsWith('/') ? `${this.domain}${image.location}` : image.location)}</image:loc>`
|
||||||
entryString += this.optionalEntry('image:caption', image.caption)
|
entryString += this.fixText(this.optionalEntry('image:caption', image.caption))
|
||||||
entryString += this.optionalEntry('image:geo_location', image.geoLocation)
|
entryString += this.fixText(this.optionalEntry('image:geo_location', image.geoLocation))
|
||||||
entryString += this.optionalEntry('image:title', image.title)
|
entryString += this.fixText(this.optionalEntry('image:title', image.title))
|
||||||
entryString += this.optionalEntry('image:license', image.license)
|
entryString += this.fixText(this.optionalEntry('image:license', image.license))
|
||||||
entryString += '</image:image>'
|
entryString += '</image:image>'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,4 +100,12 @@ export default class Sitemap {
|
|||||||
private optionalEntry(tag: string, entry?: string) {
|
private optionalEntry(tag: string, entry?: string) {
|
||||||
return entry ? `<${tag}>${entry}</${tag}>` : ''
|
return entry ? `<${tag}>${entry}</${tag}>` : ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fixText(txt: string): string {
|
||||||
|
return txt.replace(/&/g, '&')
|
||||||
|
.replace(/'/g, ''')
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user