1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/transforms/json-string.js
Kevin Ansfield 00ab9cdb1b Guard against blank strings in json-string fields (#840)
no issue

We've seen an issue where after an import a user record had `tour: ""` which meant they were unable to log in due to JSON parsing of the empty string failing.

- add a guard so that an empty string is transformed to `null` before parsing
- changed `serialised` to `serialized` to match spelling in all other serializers
2017-08-29 10:03:45 +07:00

11 lines
330 B
JavaScript

import Transform from 'ember-data/transform';
export default Transform.extend({
deserialize(serialized) {
let _serialized = serialized === '' ? null : serialized;
return JSON.parse(_serialized);
},
serialize(deserialized) {
return deserialized ? JSON.stringify(deserialized) : null;
}
});