diff --git a/examples/CreateSimpleRssFeedExample.cs b/examples/CreateSimpleRssFeedExample.cs index 3e5e429..d5695de 100644 --- a/examples/CreateSimpleRssFeedExample.cs +++ b/examples/CreateSimpleRssFeedExample.cs @@ -5,6 +5,7 @@ using Microsoft.SyndicationFeed; using Microsoft.SyndicationFeed.Rss; using System; +using System.Text; using System.IO; using System.Threading.Tasks; using System.Xml; diff --git a/examples/RssWriteItemWithCustomElementExample.cs b/examples/RssWriteItemWithCustomElementExample.cs index 414b6c5..29ce4d9 100644 --- a/examples/RssWriteItemWithCustomElementExample.cs +++ b/examples/RssWriteItemWithCustomElementExample.cs @@ -5,6 +5,7 @@ using Microsoft.SyndicationFeed; using Microsoft.SyndicationFeed.Rss; using System; +using System.Text; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; diff --git a/src/Rss/RssParser.cs b/src/Rss/RssParser.cs index 4f9b0b7..74878ef 100644 --- a/src/Rss/RssParser.cs +++ b/src/Rss/RssParser.cs @@ -11,6 +11,11 @@ namespace Microsoft.SyndicationFeed.Rss { public class RssParser : ISyndicationFeedParser { + public bool AllowNullLinks { get; set; } + + public RssParser() { } + public RssParser(bool AllowNullLinks) => this.AllowNullLinks = AllowNullLinks; + public ISyndicationCategory ParseCategory(string value) { ISyndicationContent content = ParseContent(value); @@ -192,6 +197,10 @@ public virtual ISyndicationLink CreateLink(ISyndicationContent content) throw new ArgumentNullException(nameof(content)); } + // + // Reserve for possible empty url + bool isNullUri = false; + // // Title string title = content.Value; @@ -203,21 +212,19 @@ public virtual ISyndicationLink CreateLink(ISyndicationContent content) if (url != null) { - if (!TryParseValue(url, out uri)) - { - throw new FormatException("Invalid url attribute"); - } + isNullUri = !TryParseValue(url, out uri); } else { - if (!TryParseValue(content.Value, out uri)) - { - throw new FormatException("Invalid url"); - } - + isNullUri = !TryParseValue(content.Value, out uri); title = null; } + if (!AllowNullLinks && isNullUri) + { + throw new FormatException("Invalid url"); + } + // // Length long length = 0; diff --git a/src/SyndicationLink.cs b/src/SyndicationLink.cs index 819dfde..7d90547 100644 --- a/src/SyndicationLink.cs +++ b/src/SyndicationLink.cs @@ -10,7 +10,7 @@ public sealed class SyndicationLink : ISyndicationLink { public SyndicationLink(Uri url, string relationshipType = null) { - Uri = url ?? throw new ArgumentNullException(nameof(url)); + Uri = url; RelationshipType = relationshipType; }