File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -241,12 +241,21 @@ file.readJSON = function(filepath, options) {
241241} ;
242242
243243// Read a YAML file, parse its contents, return an object.
244- file . readYAML = function ( filepath , options ) {
244+ file . readYAML = function ( filepath , options , yamlOptions ) {
245+ if ( ! options ) { options = { } ; }
246+ if ( ! yamlOptions ) { yamlOptions = { } ; }
247+
245248 var src = file . read ( filepath , options ) ;
246249 var result ;
247250 grunt . verbose . write ( 'Parsing ' + filepath + '...' ) ;
248251 try {
249- result = YAML . load ( src ) ;
252+ // use the recommended way of reading YAML files
253+ // https://github.com/nodeca/js-yaml#safeload-string---options-
254+ if ( yamlOptions . unsafeLoad ) {
255+ result = YAML . load ( src ) ;
256+ } else {
257+ result = YAML . safeLoad ( src ) ;
258+ }
250259 grunt . verbose . ok ( ) ;
251260 return result ;
252261 } catch ( e ) {
Original file line number Diff line number Diff line change @@ -452,10 +452,13 @@ exports.file = {
452452 test . done ( ) ;
453453 } ,
454454 'readYAML' : function ( test ) {
455- test . expect ( 4 ) ;
455+ test . expect ( 5 ) ;
456456 var obj ;
457457 obj = grunt . file . readYAML ( 'test/fixtures/utf8.yaml' ) ;
458- test . deepEqual ( obj , this . object , 'file should be read as utf8 by default and parsed correctly.' ) ;
458+ test . deepEqual ( obj , this . object , 'file should be safely read as utf8 by default and parsed correctly.' ) ;
459+
460+ obj = grunt . file . readYAML ( 'test/fixtures/utf8.yaml' , null , { unsafeLoad : true } ) ;
461+ test . deepEqual ( obj , this . object , 'file should be unsafely read as utf8 by default and parsed correctly.' ) ;
459462
460463 obj = grunt . file . readYAML ( 'test/fixtures/iso-8859-1.yaml' , { encoding : 'iso-8859-1' } ) ;
461464 test . deepEqual ( obj , this . object , 'file should be read using the specified encoding.' ) ;
You can’t perform that action at this time.
0 commit comments