Fix XML Data Export Error by Modifying XML Format (#13942)

* Added XML code to parse json + convert formatting before exporting as XML + XML Marshall tests

* Add linting fixes

linting errors still present in xmlMarshaller.test.js but, certain keys starting with digits (for example '800ed0') must be enclosed in quotes , so to maintain consistency within the test file I kept all keys enclosed by single quotes.

* fix(lint): unquote, EOF

Co-authored-by: SabreCat <sabe@habitica.com>
This commit is contained in:
John Li
2022-05-12 16:24:17 -04:00
committed by GitHub
parent 761d70ec55
commit d132b057eb
2 changed files with 133 additions and 1 deletions

View File

@@ -23,7 +23,33 @@ export function marshallUserData (userData) {
type: i.type,
}));
return js2xml.parse('user', userData, {
const copyUserData = JSON.parse(JSON.stringify(userData));
const newPurchased = {};
if (userData.purchased != null) {
for (const itemType in userData.purchased) {
if (userData.purchased[itemType] != null) {
if (typeof userData.purchased[itemType] === 'object') {
const fixedData = [];
for (const item in userData.purchased[itemType]) {
if (item != null) {
if (typeof userData.purchased[itemType][item] === 'object') {
fixedData.push({ item: userData.purchased[itemType][item] });
} else {
fixedData.push(item);
}
}
}
newPurchased[itemType] = fixedData;
} else {
newPurchased[itemType] = userData.purchased[itemType];
}
}
}
copyUserData.purchased = newPurchased;
}
return js2xml.parse('user', copyUserData, {
cdataInvalidChars: true,
replaceInvalidChars: true,
declaration: {