1
0
mirror of https://github.com/moodle/moodle.git synced 2025-04-23 09:23:09 +02:00

MDL-63667 amd: Check for parent template recursion

This commit is contained in:
Andrew Nicols 2018-10-18 11:54:27 +08:00 committed by Damyon Wiese
parent b51c5b929f
commit 61e0f58ca3
2 changed files with 25 additions and 10 deletions

File diff suppressed because one or more lines are too long

@ -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];
};
/**