danmactough / node-feedparser

Robust RSS, Atom, and RDF feed parsing in Node.js
Other
1.97k stars 190 forks source link

atom feed where item.link is null but item['atom:link']['@']['href'] is good #219

Closed pkra closed 6 years ago

pkra commented 7 years ago

When processing this feed, the link value is null but atom:link@href is correct.

The feed validates but is missing an xml declaration.

var FeedParser = require('feedparser');
var request = require('request'); // for fetching the feed

var req = request('https://ncatlab.org/nlab/atom_with_headlines')
var feedparser = new FeedParser();

req.on('response', function (res) {
  var stream = this; // `this` is `req`, which is a stream

  if (res.statusCode !== 200) {
    this.emit('error', new Error('Bad status code'));
  }
  else {
    stream.pipe(feedparser);
  }
});
feedparser.on('readable', function () {
  // This is where the action is!
  var stream = this; // `this` is `feedparser`, which is a stream
  var item;
  while (item = stream.read()) {
    console.log(item['atom:link']['@']['href']);
    console.log(item.link);
  }
});
danmactough commented 7 years ago

thanks @pkra. confirming this is a bug. looks like we're being too picky with some attribute checking.

danmactough commented 7 years ago

links for reference:

pkra commented 7 years ago

Thanks for taking a look and thanks for your excellent library. If you think an outsider can tackle this, I'll try to find time (though I'm afraid I only use feedparser in a side project).