Skip to content
Snippets Groups Projects
Unverified Commit 554df595 authored by Ray Schamp's avatar Ray Schamp Committed by GitHub
Browse files

Merge pull request #3619 from paulkaplan/fix-cloud-backpack

Fix backpack crashing the GUI when trying to store a cloud variable
parents 38163576 55434396
No related branches found
No related tags found
No related merge requests found
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
"immutable": "3.8.2", "immutable": "3.8.2",
"intl": "1.2.5", "intl": "1.2.5",
"jest": "^21.0.0", "jest": "^21.0.0",
"js-base64": "2.4.9",
"keymirror": "0.1.1", "keymirror": "0.1.1",
"lodash.bindall": "4.4.0", "lodash.bindall": "4.4.0",
"lodash.debounce": "4.0.8", "lodash.debounce": "4.0.8",
......
import blockToImage from './block-to-image'; import blockToImage from './block-to-image';
import jpegThumbnail from './jpeg-thumbnail'; import jpegThumbnail from './jpeg-thumbnail';
import {Base64} from 'js-base64';
const codePayload = ({blockObjects, topBlockId}) => { const codePayload = ({blockObjects, topBlockId}) => {
const payload = { const payload = {
type: 'script', // Needs to match backpack-server type name type: 'script', // Needs to match backpack-server type name
name: 'code', // All code currently gets the same name name: 'code', // All code currently gets the same name
mime: 'application/json', mime: 'application/json',
body: btoa(JSON.stringify(blockObjects)) // Base64 encode the json // Backpack expects a base64 encoded string to store. Cannot use btoa because
// the code can contain characters outside the 0-255 code-point range supported by btoa
body: Base64.encode(JSON.stringify(blockObjects)) // Base64 encode the json
}; };
return blockToImage(topBlockId) return blockToImage(topBlockId)
......
jest.mock('../../../src/lib/backpack/block-to-image', () => () => Promise.resolve('block-image'));
jest.mock('../../../src/lib/backpack/jpeg-thumbnail', () => () => Promise.resolve('thumbnail'));
import codePayload from '../../../src/lib/backpack/code-payload';
import {Base64} from 'js-base64';
describe('codePayload', () => {
test('base64 encodes the blocks as json', () => {
const blocks = '☁︎❤️🐻';
const payload = codePayload({
blockObjects: blocks
});
return payload.then(p => {
expect(
JSON.parse(Base64.decode(p.body))
).toEqual(blocks);
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment