mirror of https://github.com/vuejs/core.git
fix(runtime-dom): setting innerHTML when patching props should go through trusted types
This commit is contained in:
parent
42e8df6203
commit
d875de54e9
|
@ -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 { DeprecationTypes, compatUtils, warn } from '@vue/runtime-core'
|
||||||
import { includeBooleanAttr } from '@vue/shared'
|
import { includeBooleanAttr } from '@vue/shared'
|
||||||
|
import { unsafeToTrustedHTML } from '../nodeOps'
|
||||||
|
|
||||||
// functions. The user is responsible for using them with only trusted content.
|
// functions. The user is responsible for using them with only trusted content.
|
||||||
export function patchDOMProp(
|
export function patchDOMProp(
|
||||||
|
@ -12,11 +9,15 @@ export function patchDOMProp(
|
||||||
value: any,
|
value: any,
|
||||||
parentComponent: any,
|
parentComponent: any,
|
||||||
): void {
|
): 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') {
|
if (key === 'innerHTML' || key === 'textContent') {
|
||||||
// null value case is handled in renderer patchElement before patching
|
// null value case is handled in renderer patchElement before patching
|
||||||
// children
|
// children
|
||||||
if (value == null) return
|
if (value != null) {
|
||||||
el[key] = value
|
el[key] = key === 'innerHTML' ? unsafeToTrustedHTML(value) : value
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,8 @@ if (tt) {
|
||||||
// This function merely perform a type-level trusted type conversion
|
// This function merely perform a type-level trusted type conversion
|
||||||
// for use in `innerHTML` assignment, etc.
|
// for use in `innerHTML` assignment, etc.
|
||||||
// Be careful of whatever value passed to this function.
|
// Be careful of whatever value passed to this function.
|
||||||
const unsafeToTrustedHTML: (value: string) => TrustedHTML | string = policy
|
export const unsafeToTrustedHTML: (value: string) => TrustedHTML | string =
|
||||||
? val => policy.createHTML(val)
|
policy ? val => policy.createHTML(val) : val => val
|
||||||
: val => val
|
|
||||||
|
|
||||||
export const svgNS = 'http://www.w3.org/2000/svg'
|
export const svgNS = 'http://www.w3.org/2000/svg'
|
||||||
export const mathmlNS = 'http://www.w3.org/1998/Math/MathML'
|
export const mathmlNS = 'http://www.w3.org/1998/Math/MathML'
|
||||||
|
|
Loading…
Reference in New Issue