mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04:00
Prevent custom indents from getting into an infinite loop.
This commit is contained in:
parent
72ff6d9ead
commit
ddf3b72a7f
1 changed files with 5 additions and 1 deletions
|
@ -360,11 +360,15 @@ Blockly.Generator.prototype.provideFunction_ = function(desiredName, code) {
|
|||
var codeText = code.join('\n').replace(
|
||||
this.FUNCTION_NAME_PLACEHOLDER_REGEXP_, functionName);
|
||||
// Change all ' ' indents into the desired indent.
|
||||
// To avoid an infinite loop of replacements, change all indents to '\0'
|
||||
// character first, then replace them all with the indent.
|
||||
// We are assuming that no provided functions contain a literal null char.
|
||||
var oldCodeText;
|
||||
while (oldCodeText != codeText) {
|
||||
oldCodeText = codeText;
|
||||
codeText = codeText.replace(/^(( )*) /gm, '$1' + this.INDENT);
|
||||
codeText = codeText.replace(/^(( )*) /gm, '$1\0');
|
||||
}
|
||||
codeText = codeText.replace(/\0/g, this.INDENT);
|
||||
this.definitions_[desiredName] = codeText;
|
||||
}
|
||||
return this.functionNames_[desiredName];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue