Skip to content

Commit fa8b51d

Browse files
committed
return error if feed doesn't look like rss 1 or 2
1 parent f2bda17 commit fa8b51d

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,10 @@ Parser.parseString = function(xml, options, callback) {
244244
return parseAtomFeed(result, options, callback)
245245
} else if (result.rss && result.rss.$.version && result.rss.$.version.indexOf('2') === 0) {
246246
return parseRSS2(result, options, callback);
247-
} else {
247+
} else if (result['rdf:RDF']) {
248248
return parseRSS1(result, options, callback);
249+
} else {
250+
return callback(new Error("Feed not recognized as RSS 1 or 2."))
249251
}
250252
});
251253
}

test/input/unrecognized.rss

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<head><title>Document Moved</title></head>
2+
<body><h1>Object Moved</h1>This document may be found <a HREF="http://fishhawk2.marketwatch.com/rss/pf/">here</a></body>

test/parser.js

+7
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ describe('Parser', function() {
7070
testParseForFile('narro', 'rss', done);
7171
});
7272

73+
it('should throw error for unrecognized', function(done) {
74+
Parser.parseFile(__dirname + '/input/unrecognized.rss', (err, parsed) => {
75+
Expect(err.message).to.contain('Feed not recognized as RSS');
76+
done();
77+
})
78+
})
79+
7380
it('should parse custom fields', function(done) {
7481
var options = {
7582
customFields: {

0 commit comments

Comments
 (0)