Files
habitica/website/server/libs/xmlMarshaller.js
Helcostr 19ec9162c5 Prevent invalid characters from being used in XML. (#13181)
Patching issue of never returning XML, at the cost of "obfuscated" xml key
2021-04-19 19:08:17 +10:00

34 lines
841 B
JavaScript

import _ from 'lodash';
import * as js2xml from 'js2xmlparser';
export function marshallUserData (userData) {
// object maps can't be marshalled to XML
userData.inbox.messages = _(userData.inbox.messages)
.map(m => {
m.flags = Object.keys(m.flags);
return m;
})
.value();
userData.newMessages = _.map(userData.newMessages, (msg, id) => ({ id, ...msg }));
// _id gets parsed as a bytearray => which gets cast to a chararray => "weird chars"
userData.unpinnedItems = userData.unpinnedItems.map(i => ({
path: i.path,
type: i.type,
}));
userData.pinnedItems = userData.pinnedItems.map(i => ({
path: i.path,
type: i.type,
}));
return js2xml.parse('user', userData, {
cdataInvalidChars: true,
replaceInvalidChars: true,
declaration: {
include: false,
},
});
}