Limit join result length to 10240

This commit is contained in:
Paul Kaplan 2018-12-17 16:25:39 -05:00
parent ebe06a97d9
commit 48ae666458
2 changed files with 15 additions and 1 deletions

View file

@ -91,7 +91,9 @@ class Scratch3OperatorsBlocks {
}
join (args) {
return Cast.toString(args.STRING1) + Cast.toString(args.STRING2);
// Limit result to 10240 characters: https://github.com/LLK/scratch-vm/issues/922
return (Cast.toString(args.STRING1) + Cast.toString(args.STRING2))
.slice(0, 10240);
}
letterOf (args) {

View file

@ -122,6 +122,18 @@ test('random - reverse', t => {
test('join', t => {
t.strictEqual(blocks.join({STRING1: 'foo', STRING2: 'bar'}), 'foobar');
t.strictEqual(blocks.join({STRING1: '1', STRING2: '2'}), '12');
t.strictEqual(blocks.join({STRING1: '1', STRING2: '2'}), '12');
t.end();
});
test('join result length does not exceed 10240', t => {
const sixThousandCharacterString = Array(6000)
.fill('a')
.join('');
t.strictEqual(blocks.join({
STRING1: sixThousandCharacterString,
STRING2: sixThousandCharacterString
}).length, 10240);
t.end();
});