@@ -14,7 +14,8 @@ var Chunk = require("./chunk");
1414var defaults = {
1515 extensions : null ,
1616 filter : null ,
17- matchPattern : null
17+ matchPattern : null ,
18+ limit : 5000
1819} ;
1920Object . defineProperty ( defaults , "directory" , {
2021 enumerable : true ,
@@ -32,8 +33,14 @@ module.exports = function cssImport(options) {
3233 return x . trim ( ) ;
3334 } ) ;
3435 }
35-
36+
37+ var stream ;
38+ var cssCount = 0 ;
39+
3640 function fileContents ( data , encoding , callback ) {
41+ if ( ! stream ) {
42+ stream = this ;
43+ }
3744 var chunk = Chunk . create ( data , { directory : options . directory } ) ;
3845 //console.log("chunk.isVinyl", chunk.isVinyl);
3946 // https://github.com/kevva/import-regex/
@@ -61,6 +68,11 @@ module.exports = function cssImport(options) {
6168 fileArray [ index ] = format ( "importing file %j" , pathObject ) ;
6269 lastPos = importRe . lastIndex ;
6370 // Start resolving.
71+ // console.log("Start resolving", cssCount++, pathObject);
72+ if ( ++ cssCount > options . limit ) {
73+ stream . emit ( "error" , new Error ( "Exceed limit. Recursive include?" ) ) ;
74+ return ;
75+ }
6476 count ++ ;
6577 resolvePath ( pathObject , onResolvePath ) ;
6678 }
@@ -98,13 +110,12 @@ module.exports = function cssImport(options) {
98110 if ( fileArray . length > 0 ) {
99111 contents = fileArray . join ( "" ) ;
100112 }
101- // todo: 1. options for max recursive
102113 if ( ! state . done ) {
103114 //console.log("chunk.isVinyl", chunk.isVinyl);
104115 var nextChunk ;
105116 if ( chunk . isVinyl ) {
106117 chunk . vinyl . contents = new Buffer ( contents ) ;
107- chunk . vinyl . base = state . directory ;
118+ chunk . vinyl . base = state . directory ;
108119 nextChunk = chunk . vinyl ;
109120 } else {
110121 nextChunk = Chunk . create ( {
0 commit comments