Ghost/ghost/admin/app/transforms/json-string.js
Kevin Ansfield 18d7a7b55d 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

12 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;
}
});