Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handles broken RSS feeds that may not include an <rss> declaration. #179

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
----------------------------------------------------------------------
node-feedparser is released under the MIT License
Copyright (c) 2011-2018 Dan MacTough and contributors
Copyright (c) 2022 Newstex LLC

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand Down
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# Feedparser - Robust RSS, Atom, and RDF feed parsing in Node.js

[![Greenkeeper badge](https://badges.greenkeeper.io/danmactough/node-feedparser.svg)](https://greenkeeper.io/)

[![Join the chat at https://gitter.im/danmactough/node-feedparser](https://badges.gitter.im/danmactough/node-feedparser.svg)](https://gitter.im/danmactough/node-feedparser?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

[![Build Status](https://secure.travis-ci.org/danmactough/node-feedparser.png?branch=master)](https://travis-ci.org/danmactough/node-feedparser)

[![NPM](https://nodei.co/npm/feedparser.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/feedparser/)
**NOTE**: This is a fork of the node-feedparser library which supports invalid RSS feeds (missing opening tags, closing tags, etc).
It takes an approch of "try to make sense of whatever input you get", rather than requiring strict RSS standards.

Feedparser is for parsing RSS, Atom, and RDF feeds in node.js.

Expand All @@ -15,6 +10,7 @@ It has a couple features you don't usually see in other feed parsers:
1. It resolves relative URLs (such as those seen in Tim Bray's "ongoing" [feed](https://www.tbray.org/ongoing/ongoing.atom)).
2. It properly handles XML namespaces (including those in unusual feeds
that define a non-default namespace for the main feed elements).
3. It resolves issues with missing `<rss>` and `<channel>` envelops

## Installation

Expand Down Expand Up @@ -185,12 +181,11 @@ e.g., `meta['atom:subtitle']['#']`.

## Help

- Don't be afraid to report an [issue](https://github.com/danmactough/node-feedparser/issues).
- You can drop by [Gitter](https://gitter.im/danmactough/node-feedparser?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge), too.
- Don't be afraid to report an [issue](https://github.com/Newstex/node-feedparser/issues).

## Contributors

View all the [contributors](https://github.com/danmactough/node-feedparser/graphs/contributors).
View all the [contributors](https://github.com/Newstex/node-feedparser/graphs/contributors).

Although `node-feedparser` no longer shares any code with `node-easyrss`, it was
the original inspiration and a starting point.
Expand All @@ -200,6 +195,7 @@ the original inspiration and a starting point.
(The MIT License)

Copyright (c) 2011-2020 Dan MacTough and contributors
Copyright (c) 2022 Newstex LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the 'Software'), to deal in
Expand Down
10 changes: 9 additions & 1 deletion lib/feedparser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ FeedParser.prototype.handleOpenTag = function (node){
this.xhtml['#'] += '>';
} else if ( this.stack.length === 0 &&
(n['#name'] === 'rss' ||
(!this.meta['#type'] && n['#name'] === 'channel') ||
(n['#local'] === 'rdf' && _.nslookup([n['#uri']], 'rdf')) ||
(n['#local'] === 'feed'&& _.nslookup([n['#uri']], 'atom')) ) ) {
Object.keys(n['@']).forEach(function(name) {
Expand All @@ -191,6 +192,10 @@ FeedParser.prototype.handleOpenTag = function (node){
this.meta['#type'] = 'rss';
this.meta['#version'] = n['@']['version'];
break;
case 'channel':
this.meta['#type'] = 'rss';
this.meta['#version'] = n['@']['version'];
break;
case 'rdf':
this.meta['#type'] = 'rdf';
this.meta['#version'] = n['@']['version'] || '1.0';
Expand Down Expand Up @@ -295,6 +300,7 @@ FeedParser.prototype.handleCloseTag = function (el){

if (node['#name'] === 'item' ||
node['#name'] === 'entry' ||
node['#name'] === 'article' ||
(node['#local'] === 'item' && (node['#prefix'] === '' || node['#type'] === 'rdf')) ||
(node['#local'] == 'entry' && (node['#prefix'] === '' || node['#type'] === 'atom'))) { // We have an article!

Expand Down Expand Up @@ -798,11 +804,13 @@ FeedParser.prototype.handleItem = function handleItem (node, type, options){
case('title'):
item.title = _.get(el);
break;
case('description'):
case('summary'):
item.summary = _.get(el);
if (!item.description) item.description = _.get(el);
break;
case('description'):
item.description = _.get(el);
break;
case('content'):
case('content:encoded'):
item.description = _.get(el);
Expand Down
Loading