From bd03f1ca70b0fe2d3ed22d98af2e83d8cbcf5f43 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Thu, 14 Sep 2023 10:08:11 -0400 Subject: [PATCH] Prevent setting a propery that has a getter. (mathjax/MathJax#3098) --- ts/components/global.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/ts/components/global.ts b/ts/components/global.ts index 65825b611..adec367c2 100644 --- a/ts/components/global.ts +++ b/ts/components/global.ts @@ -78,18 +78,21 @@ export function isObject(x: any): boolean { * Combine user-produced configuration with existing defaults. Values * from src will replace those in dst. * - * @param {any} dst The destination config object (to be merged into) - * @param {any} src The source configuration object (to replace defaul values in dst} - * @return {any} The resulting (modified) config object + * @param {any} dst The destination config object (to be merged into) + * @param {any} src The source configuration object (to replace defaul values in dst} + * @param {boolean} check True when combining into MathJax._ to avoid setting getter properties + * @return {any} The resulting (modified) config object */ -export function combineConfig(dst: any, src: any): any { +export function combineConfig(dst: any, src: any, check: boolean = false): any { for (const id of Object.keys(src)) { - if (id === '__esModule') continue; + if (id === '__esModule' || dst[id] === src[id]) continue; if (isObject(dst[id]) && isObject(src[id]) && !(src[id] instanceof Promise) /* needed for IE polyfill */) { - combineConfig(dst[id], src[id]); - } else if (src[id] !== null && src[id] !== undefined && dst[id] !== src[id]) { - dst[id] = src[id]; + combineConfig(dst[id], src[id], check || id === '_'); + } else if (src[id] !== null && src[id] !== undefined) { + if (!check || !Object.getOwnPropertyDescriptor(dst, id)?.get) { + dst[id] = src[id]; + } } } return dst;