@@ -132,14 +132,16 @@ var parseRSS2 = function(xmlObj, options, callback) {
132
132
}
133
133
134
134
var parseRSS = function ( channel , items , options , callback ) {
135
+ items = items || [ ] ;
136
+ options . customFields = options . customFields || { } ;
135
137
var itemFields = ITEM_FIELDS . concat ( options . customFields . item || [ ] ) ;
136
138
var feedFields = FEED_FIELDS . concat ( options . customFields . feed || [ ] ) ;
137
139
138
140
var json = { feed : { entries : [ ] } } ;
139
141
140
142
if ( channel [ 'atom:link' ] ) json . feed . feedUrl = channel [ 'atom:link' ] [ 0 ] . $ . href ;
141
143
copyFromXML ( channel , json . feed , feedFields ) ;
142
- ( items || [ ] ) . forEach ( function ( item ) {
144
+ items . forEach ( function ( item ) {
143
145
var entry = { } ;
144
146
copyFromXML ( item , entry , itemFields ) ;
145
147
if ( item . enclosure ) {
@@ -211,7 +213,7 @@ var decorateItunes = function decorateItunes(json, channel) {
211
213
}
212
214
213
215
copyFromXML ( channel , json . feed . itunes , PODCAST_FEED_FIELDS ) ;
214
- ( items ) . forEach ( function ( item , index ) {
216
+ items . forEach ( function ( item , index ) {
215
217
var entry = json . feed . entries [ index ] ;
216
218
entry . itunes = { } ;
217
219
copyFromXML ( item , entry . itunes , PODCAST_ITEM_FIELDS ) ;
@@ -227,10 +229,6 @@ Parser.parseString = function(xml, options, callback) {
227
229
callback = options ;
228
230
options = { } ;
229
231
}
230
- options . customFields = options . customFields || { } ;
231
- var itemFields = ITEM_FIELDS . concat ( options . customFields . item || [ ] ) ;
232
- var feedFields = FEED_FIELDS . concat ( options . customFields . feed || [ ] ) ;
233
-
234
232
XML2JS . parseString ( xml , function ( err , result ) {
235
233
if ( err ) return callback ( err ) ;
236
234
if ( result . feed ) {
@@ -278,7 +276,7 @@ Parser.parseURL = function(feedUrl, options, callback) {
278
276
req . on ( 'error' , callback ) ;
279
277
}
280
278
281
- Parser . parseFile = function ( file , options , callback ) {
279
+ Parser . parseFile = function ( file , options , callback ) {
282
280
FS . readFile ( file , 'utf8' , function ( err , contents ) {
283
281
return Parser . parseString ( contents , options , callback ) ;
284
282
} )
0 commit comments