Skip to content

Commit e65ffec

Browse files
committed
fix: ensure to escape values in a collection
1 parent 6cbeec9 commit e65ffec

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/metascraper/src/get-data.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { map, fromPairs, isEmpty } = require('lodash')
3+
const { map, fromPairs, isEmpty, isArray } = require('lodash')
44
const xss = require('xss')
55

66
const getValue = async ({ htmlDom, url, conditions, meta }) => {
@@ -15,11 +15,16 @@ const getValue = async ({ htmlDom, url, conditions, meta }) => {
1515
return value
1616
}
1717

18+
const escapeValue = (value, { escape }) => {
19+
if (!escape) return value
20+
return isArray(value) ? map(value, xss) : xss(value)
21+
}
22+
1823
const getData = async ({ rules, htmlDom, url, escape }) => {
1924
const data = await Promise.all(
2025
map(rules, async ([propName, conditions]) => {
2126
const rawValue = await getValue({ htmlDom, url, conditions })
22-
const value = isEmpty(rawValue) ? null : escape ? xss(rawValue) : rawValue
27+
const value = isEmpty(rawValue) ? null : escapeValue(rawValue, { escape })
2328
return [propName, value]
2429
})
2530
)

0 commit comments

Comments
 (0)