MDL-63667 amd: Check for parent template recursion

This commit is contained in:
Andrew Nicols
2018-10-18 12:12:43 +08:00
committed by Damyon Wiese
parent 1a3a8a9d6d
commit 0ede37a30c
2 changed files with 25 additions and 10 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+24 -9
View File
@@ -657,24 +657,39 @@ define(['core/mustache',
return cachePartialPromises[searchKey];
}
var cachePartialPromise = this.getTemplate(templateName).then(function(templateSource) {
// This promise will not be resolved until all child partials are also resolved and ready.
// We create it here to allow us to check for recursive inclusion of templates.
cachePartialPromises[searchKey] = $.Deferred();
this.getTemplate(templateName)
.then(function(templateSource) {
var partials = this.scanForPartials(templateSource);
// Ignore templates that include themselves.
var uniquePartials = partials.filter(function(partialName) {
// Check for recursion.
if (typeof cachePartialPromises[this.currentThemeName + '/' + partialName] !== 'undefined') {
// Ignore templates which include their parent.
return false;
}
// Ignore templates that include themselves.
return partialName != templateName;
});
}.bind(this));
// Fetch any partial which has not already been fetched.
var fetchThemAll = uniquePartials.map(function(partialName) {
return this.cachePartials(partialName);
}.bind(this));
return $.when.apply($, fetchThemAll).then(function() {
return templateSource;
// Resolve the templateName promise when all of the children are resolved.
return $.when.apply($, fetchThemAll)
.then(function() {
return cachePartialPromises[searchKey].resolve(templateSource);
});
}.bind(this));
}.bind(this))
.catch(cachePartialPromises[searchKey].reject);
cachePartialPromises[searchKey] = cachePartialPromise;
return cachePartialPromise;
return cachePartialPromises[searchKey];
};
/**