xp icon indicating copy to clipboard operation
xp copied to clipboard

js authLib.modifyProfile() stores array with single value as string

Open ComLock opened this issue 8 years ago • 3 comments

Enonic version: 6.9.2 OS: Mac OSX

When I store a JS object (might be a deep structure) in Enonic XP, I expect getting the exact same object back when I fetch it back from Enonic XP.

But that is not the case.

Any array within the structure which has a single value get stored as a string instead of an array with a single value.

For site-config, content-types, component config, etc we know which value should be an array, based on the xml file, and so we can use lib.util.data.forcearray to workaround the problem. But it's not pretty.

When it comes to undefined dynamic structures it is a bigger problem.

I guess I could workaround it by using JSON.stringify when I store data, and JSON.parse when I fetch data. Also not pretty.

I hope this gets fixed in Enonic XP 7.0

ComLock avatar Mar 22 '17 16:03 ComLock

I've made enonify so one can at least diff against what enonic has "changed" upon storage. https://github.com/ComLock/enonic-js-utils/blob/main/src/storage/indexing/enonify.ts#L11

ComLock avatar Aug 16 '21 10:08 ComLock

This seems to be general case for all single value arrays, not just authLib.modifyPrifile @ComLock , right?

rymsha avatar Nov 23 '21 07:11 rymsha

I can't remember anything about something I reported 4 years ago :) If it is still reproduceable, take it from there?

ComLock avatar Nov 23 '21 08:11 ComLock

This is a general case for all "array" fields: internally "everything" (except null) is stored as an array, but single value arrays returned as value itself

rymsha avatar Dec 19 '22 09:12 rymsha

Yes, this is the forceArray problem.

ComLock avatar Dec 19 '22 09:12 ComLock