Skip to content

Commit

Permalink
feat: Replace \\' by '
Browse files Browse the repository at this point in the history
  • Loading branch information
lsaudon committed Feb 2, 2024
1 parent 7303cf3 commit 724854c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/extension/toJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ export function toJson(
};
map.set(`@${key}`, entry);
}

return JSON.stringify(Object.fromEntries(sorted ? sortArb(map) : map), null, 2);
return JSON.stringify(
Object.fromEntries(sorted ? sortArb(map) : map),
(_key: string, _value: unknown): unknown => {
if (typeof _value === 'string') {
return _value.replace(/\\'/gu, "'");
}
return _value;
},
2,
);
}
7 changes: 7 additions & 0 deletions src/test/suite/toJson.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ describe('toJson', () => {
}`);
});

it('should return json when mesages with double backslash and apostrophe', () => {
expect(toJson(defaultArbJson, true, 'helloWorld', null, "Hello\\'World", [], false)).to.be.equal(`{
"@@locale": "fr",
"helloWorld": "Hello'World"
}`);
});

it('should return json when message with description for template file', () => {
expect(
toJson(
Expand Down

0 comments on commit 724854c

Please sign in to comment.