Skip to content

Commit

Permalink
Prevent infinite recursion in DFS
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitgeist87 committed Dec 21, 2015
1 parent 2a21d56 commit 02894e1
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;

This comment has been minimized.

Copy link
@Golmote

Golmote Feb 3, 2016

Contributor

Are we using an object as the key here and below? Does this work?

This comment has been minimized.

Copy link
@zeitgeist87

zeitgeist87 Feb 3, 2016

Author Collaborator

You are right it does not work. The object gets stringified to "[object Object]" and that is used as an index. This is a serious bug.

This comment has been minimized.

Copy link
@zeitgeist87

zeitgeist87 Feb 3, 2016

Author Collaborator

@Golmote I don't see a quick fix for this. We have to remove it immediately and release a hot fix version of Prism 1.4.1. What do you think?

This comment has been minimized.

Copy link
@zeitgeist87

zeitgeist87 Feb 3, 2016

Author Collaborator

@Golmote I've created a PR with a fix for this #877

_.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 02894e1

Please sign in to comment.