@@ -54,15 +54,8 @@ var _DEFAULT_DELIMITER = '%';
5454var _DEFAULT_LOCALS_NAME = 'locals' ;
5555var _NAME = 'ejs' ;
5656var _REGEX_STRING = '(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)' ;
57- var _OPTS = [ 'cache' , 'filename' , 'delimiter' , 'scope' , 'context' ,
58- 'debug' , 'compileDebug' , 'client' , '_with' , 'root' , 'rmWhitespace' ,
59- 'strict' , 'localsName' ] ;
60- var _OPTS_IN_DATA_BLACKLIST = {
61- cache : true ,
62- filename : true ,
63- root : true ,
64- localsName : true
65- } ;
57+ var _OPTS = [ 'delimiter' , 'scope' , 'context' , 'debug' , 'compileDebug' ,
58+ 'client' , '_with' , 'rmWhitespace' , 'strict' ] ;
6659var _BOM = / ^ \uFEFF / ;
6760
6861/**
@@ -260,31 +253,6 @@ function rethrow(err, str, filename, lineno){
260253 throw err ;
261254}
262255
263- /**
264- * Copy properties in data object that are recognized as options to an
265- * options object.
266- *
267- * This is used for compatibility with earlier versions of EJS and Express.js.
268- *
269- * @memberof module:ejs-internal
270- * @param {Object } data data object
271- * @param {Options } opts options object
272- * @static
273- */
274-
275- function cpOptsInData ( data , opts ) {
276- _OPTS . forEach ( function ( p ) {
277- if ( typeof data [ p ] != 'undefined' ) {
278- // Disallow passing potentially dangerous opts in the data
279- // These opts should not be settable via a `render` call
280- if ( _OPTS_IN_DATA_BLACKLIST [ p ] ) {
281- return ;
282- }
283- opts [ p ] = data [ p ] ;
284- }
285- } ) ;
286- }
287-
288256function stripSemi ( str ) {
289257 return str . replace ( / ; ( \s * $ ) / , '$1' ) ;
290258}
@@ -341,7 +309,7 @@ exports.render = function (template, d, o) {
341309 // No options object -- if there are optiony names
342310 // in the data, copy them to options
343311 if ( arguments . length == 2 ) {
344- cpOptsInData ( data , opts ) ;
312+ utils . shallowCopyFromList ( opts , data , _OPTS ) ;
345313 }
346314
347315 return handleCache ( opts , template ) ( data ) ;
@@ -366,21 +334,27 @@ exports.renderFile = function () {
366334 var cb = args . pop ( ) ;
367335 var data = args . shift ( ) || { } ;
368336 var opts = args . pop ( ) || { } ;
337+ var optsKeys = _OPTS . slice ( ) ;
369338 var result ;
370339
371340 // Don't pollute passed in opts obj with new vals
372341 opts = utils . shallowCopy ( { } , opts ) ;
373342
343+ // We don't allow 'cache' option to be passed in the data obj
344+ // for the normal `render` call, but this is where Expres puts it
345+ // so we make an exception for `renderFile`
346+ optsKeys . push ( 'cache' ) ;
347+
374348 // No options object -- if there are optiony names
375349 // in the data, copy them to options
376350 if ( arguments . length == 3 ) {
377351 // Express 4
378352 if ( data . settings && data . settings [ 'view options' ] ) {
379- cpOptsInData ( data . settings [ 'view options' ] , opts ) ;
353+ utils . shallowCopyFromList ( opts , data . settings [ 'view options' ] , optsKeys ) ;
380354 }
381355 // Express 3 and lower
382356 else {
383- cpOptsInData ( data , opts ) ;
357+ utils . shallowCopyFromList ( opts , data , optsKeys ) ;
384358 }
385359 }
386360 opts . filename = filename ;
0 commit comments