Skip to content

Commit b4b6c58

Browse files
committed
fix(unhead): safer handling of input
1 parent e51b646 commit b4b6c58

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

packages/unhead/src/utils/dedupe.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export function dedupeKey<T extends HeadTag>(tag: T): string | undefined {
3737
// open graph props can have multiple tags with the same property
3838
if (props[n] !== undefined) {
3939
const propValue = props[n]
40-
const isStructured = propValue.includes(':')
41-
const isStandardSingle = StandardSingleMetaTags.has(propValue)
40+
const isStructured = propValue && typeof propValue === 'string' && propValue.includes(':')
41+
const isStandardSingle = propValue && StandardSingleMetaTags.has(propValue)
4242
const shouldAlwaysDedupe = isStructured || isStandardSingle
4343
const keyPart = (!shouldAlwaysDedupe && tag.key) ? `:key:${tag.key}` : ''
4444
return `${name}:${propValue}${keyPart}`

packages/unhead/src/utils/normalize.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ function normalizeStyleClassProps(
99
const store = key === 'style' ? new Map() : new Set()
1010

1111
function processValue(rawValue: string) {
12-
const value = rawValue.trim()
12+
if (rawValue == null || rawValue === undefined)
13+
return
14+
const value = String(rawValue).trim()
1315
if (!value)
1416
return
1517

1618
if (key === 'style') {
17-
const [k, ...v] = value.split(':').map(s => s.trim())
19+
const [k, ...v] = value.split(':').map(s => s ? s.trim() : '')
1820
if (k && v.length)
1921
// @ts-expect-error untyped
2022
store.set(k, v.join(':'))
@@ -38,7 +40,7 @@ function normalizeStyleClassProps(
3840
if (v && v !== 'false') {
3941
key === 'style'
4042
// @ts-expect-error untyped
41-
? store.set(k.trim(), v)
43+
? store.set(String(k).trim(), String(v))
4244
: processValue(k)
4345
}
4446
})

0 commit comments

Comments
 (0)