Skip to content

Commit

Permalink
fix(runtime-dom): setting innerHTML when patching props should go thr…
Browse files Browse the repository at this point in the history
…ough trusted types
  • Loading branch information
yyx990803 committed Aug 28, 2024
1 parent 42e8df6 commit d875de5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
13 changes: 7 additions & 6 deletions packages/runtime-dom/src/modules/props.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// __UNSAFE__
// Reason: potentially setting innerHTML.
// This can come from explicit usage of v-html or innerHTML as a prop in render

import { DeprecationTypes, compatUtils, warn } from '@vue/runtime-core'
import { includeBooleanAttr } from '@vue/shared'
import { unsafeToTrustedHTML } from '../nodeOps'

// functions. The user is responsible for using them with only trusted content.
export function patchDOMProp(
Expand All @@ -12,11 +9,15 @@ export function patchDOMProp(
value: any,
parentComponent: any,
): void {
// __UNSAFE__
// Reason: potentially setting innerHTML.
// This can come from explicit usage of v-html or innerHTML as a prop in render
if (key === 'innerHTML' || key === 'textContent') {
// null value case is handled in renderer patchElement before patching
// children
if (value == null) return
el[key] = value
if (value != null) {
el[key] = key === 'innerHTML' ? unsafeToTrustedHTML(value) : value
}
return
}

Expand Down
5 changes: 2 additions & 3 deletions packages/runtime-dom/src/nodeOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ if (tt) {
// This function merely perform a type-level trusted type conversion
// for use in `innerHTML` assignment, etc.
// Be careful of whatever value passed to this function.
const unsafeToTrustedHTML: (value: string) => TrustedHTML | string = policy
? val => policy.createHTML(val)
: val => val
export const unsafeToTrustedHTML: (value: string) => TrustedHTML | string =
policy ? val => policy.createHTML(val) : val => val

export const svgNS = 'http://www.w3.org/2000/svg'
export const mathmlNS = 'http://www.w3.org/1998/Math/MathML'
Expand Down

0 comments on commit d875de5

Please sign in to comment.