Skip to content

Commit

Permalink
Merge pull request #841 from zeitgeist87/TestBranch
Browse files Browse the repository at this point in the history
Prevent infinite recursion in DFS
  • Loading branch information
LeaVerou committed Dec 24, 2015
2 parents 9ca0c9b + 02894e1 commit 292cebd
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,19 @@ var _ = _self.Prism = {
},

// Traverse a language definition with Depth First Search
DFS: function(o, callback, type) {
DFS: function(o, callback, type, visited) {
visited = visited || {};
for (var i in o) {
if (o.hasOwnProperty(i)) {
callback.call(o, i, o[i], type || i);

if (_.util.type(o[i]) === 'Object') {
_.languages.DFS(o[i], callback);
if (_.util.type(o[i]) === 'Object' && !visited[o[i]]) {
visited[o[i]] = true;
_.languages.DFS(o[i], callback, null, visited);
}
else if (_.util.type(o[i]) === 'Array') {
_.languages.DFS(o[i], callback, i);
else if (_.util.type(o[i]) === 'Array' && !visited[o[i]]) {
visited[o[i]] = true;
_.languages.DFS(o[i], callback, i, visited);
}
}
}
Expand Down

0 comments on commit 292cebd

Please sign in to comment.