Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/CreateSimpleRssFeedExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions examples/RssWriteItemWithCustomElementExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 16 additions & 9 deletions src/Rss/RssParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/SyndicationLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down