From 2d766c234955230e6357845b4d69ebba51f04452 Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Thu, 8 Feb 2024 17:03:28 +0200 Subject: [PATCH] getJson function of localizable string should return copy of the object fix #7837 --- src/localizablestring.ts | 8 ++++++-- tests/localizablestringtests.ts | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/localizablestring.ts b/src/localizablestring.ts index f42001d355..9a0cd44c58 100644 --- a/src/localizablestring.ts +++ b/src/localizablestring.ts @@ -31,7 +31,7 @@ export class LocalizableString implements ILocalizableString { } public static defaultRenderer = "sv-string-viewer"; public static editableRenderer = "sv-string-editor"; - private values = {}; + private values: any = {}; private htmlValues = {}; private renderedText: string; private calculatedTextValue: string; @@ -268,7 +268,11 @@ export class LocalizableString implements ILocalizableString { !settings.serialization.localizableStringSerializeAsObject ) return (this).values[keys[0]]; - return this.values; + const res: any = {}; + for(let key in this.values) { + res[key] = this.values[key]; + } + return res; } public setJson(value: any): void { if (!!this.sharedData) { diff --git a/tests/localizablestringtests.ts b/tests/localizablestringtests.ts index 4b50f021c9..e618feb838 100644 --- a/tests/localizablestringtests.ts +++ b/tests/localizablestringtests.ts @@ -856,3 +856,12 @@ QUnit.test("Support defaultValue for localizable strings", function (assert) { assert.equal(locStr2.text, "str2", "str2 #3"); assert.equal(locStr3.text, "Abschließen", "str3 #3"); }); +QUnit.test("getJSON should copy values", function (assert) { + const owner = new LocalizableOwnerTester(""); + const locStr = new LocalizableString(owner, true); + locStr.setJson({ default: "str", de: "de: str" }); + assert.deepEqual(locStr.getJson(), { default: "str", de: "de: str" }, "getJson #1"); + const json = locStr.getJson(); + json["fr"] = "fr: str"; + assert.deepEqual(locStr.getJson(), { default: "str", de: "de: str" }, "getJson #2"); +});