Skip to content

Commit

Permalink
getJson function of localizable string should return copy of the object
Browse files Browse the repository at this point in the history
fix #7837 (#7838)
  • Loading branch information
andrewtelnov authored Feb 8, 2024
1 parent c63142e commit 479474d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/localizablestring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -268,7 +268,11 @@ export class LocalizableString implements ILocalizableString {
!settings.serialization.localizableStringSerializeAsObject
)
return (<any>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) {
Expand Down
9 changes: 9 additions & 0 deletions tests/localizablestringtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});

0 comments on commit 479474d

Please sign in to comment.