Skip to content

Commit

Permalink
Merge pull request #26 from download13/validation-fixes
Browse files Browse the repository at this point in the history
Validation fixes
  • Loading branch information
jpmonette committed Sep 16, 2014
2 parents 761272c + 38319e3 commit 1e80b3d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var generatorName = 'Feed for Node.js';
// Feed Main Module
// ============================================================================
function Feed(options) {
this.id = options.id;
this.title = options.title;
this.description = options.description;
this.link = options.link;
Expand All @@ -32,6 +33,7 @@ function Feed(options) {
author: options.author,
contributor: options.contributor, // Atom only
guid: options.guid,
id: options.id,
content: options.content,
copyright: options.copyright // Atom only
};
Expand Down Expand Up @@ -104,6 +106,10 @@ function atom_1_0(options) {
/**************************************************************************
* "feed" node: REQUIRED elements
*************************************************************************/
if(options.id == undefined)
throw new Error('feed id is mandatory');
else
feed.push({ id: options.id });

if(options.title == undefined)
throw new Error('feed title is mandatory');
Expand All @@ -115,8 +121,6 @@ function atom_1_0(options) {
else
if(!validateURL(options.link))
throw new Error('invalid feed link');
else
feed.push({ link: options.link });

if(Object.prototype.toString.call(options.updated) === '[object Date]')
feed.push({ updated: RFC3339(options.updated) });
Expand Down Expand Up @@ -213,7 +217,7 @@ function atom_1_0(options) {

var entry = [
{ title: { _attr: { type: 'html' }, _cdata: entries[i].title }},
{ id: entries[i].link },
{ id: entries[i].id || entries[i].link },
{ link: [{ _attr: { href: entries[i].link } }]},
{ updated: RFC3339(entries[i].date) }
];
Expand Down

0 comments on commit 1e80b3d

Please sign in to comment.