2016-03-18 19:51:40 -04:00
|
|
|
/**
|
|
|
|
* Converts string from unpack method into a project object. Note: this method
|
|
|
|
* will be expanded greatly in the future in order to support the Scratch 1.4
|
|
|
|
* file format. For now, this is nothing but an (awkward) async wrapper around
|
|
|
|
* the `JSON.parse` function.
|
2018-03-24 11:09:43 -04:00
|
|
|
* @param {string} input Stringified JSON object
|
|
|
|
* @param {Function} callback Returns error or parsed JSON object
|
|
|
|
* @return {void}
|
2016-03-18 19:51:40 -04:00
|
|
|
*/
|
2016-03-15 10:31:35 -04:00
|
|
|
module.exports = function (input, callback) {
|
2018-05-02 17:10:52 -04:00
|
|
|
var result;
|
2016-03-18 19:51:40 -04:00
|
|
|
try {
|
2019-02-25 17:02:30 -05:00
|
|
|
// The input is a JSON string, which may contain control characters
|
|
|
|
// that should be removed. See LLK/scratch-vm#1077
|
|
|
|
// So far we've only encountered the backspace control character,
|
|
|
|
// so remove that specific one before continuing.
|
|
|
|
// SB2 JSONs and SB3 JSONs have different versions of the
|
|
|
|
// character serialized (e.g. \u0008 and \b), strip out both versions
|
|
|
|
result = JSON.parse(input.replace(/\\b|\\u0008/g, ''));
|
2016-03-18 19:51:40 -04:00
|
|
|
} catch (e) {
|
|
|
|
return callback(e.toString());
|
2016-03-15 10:31:35 -04:00
|
|
|
}
|
2018-05-02 17:10:52 -04:00
|
|
|
return callback(null, result);
|
2016-03-15 10:31:35 -04:00
|
|
|
};
|