Skip to content

Commit

Permalink
Prevent setting a propery that has a getter. (mathjax/MathJax#3098)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpvc committed Sep 14, 2023
1 parent a662fa7 commit bd03f1c
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions ts/components/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bd03f1c

Please sign in to comment.