From ef61ce278c4b2bbaf6ae41c372abf242c762c0ba Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Tue, 16 Sep 2014 09:43:32 -0400 Subject: [PATCH] Clean up unescaped & in feed XML --- Application/FeedCenter.csproj | 14 +++++++++----- Application/Feeds/Feed.cs | 7 ++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Application/FeedCenter.csproj b/Application/FeedCenter.csproj index 4b804a2..ba12c98 100644 --- a/Application/FeedCenter.csproj +++ b/Application/FeedCenter.csproj @@ -17,10 +17,14 @@ {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 false - SAK - SAK - SAK - SAK + + + + + + + + \\server\d\FeedCenter\ true Unc @@ -54,7 +58,7 @@ false - AnyCPU + x86 pdbonly true bin\Release\ diff --git a/Application/Feeds/Feed.cs b/Application/Feeds/Feed.cs index 5f51765..fe3e0c2 100644 --- a/Application/Feeds/Feed.cs +++ b/Application/Feeds/Feed.cs @@ -1,4 +1,5 @@ -using Common.Debug; +using System.Text.RegularExpressions; +using Common.Debug; using Common.Xml; using FeedCenter.FeedParsers; using System; @@ -172,6 +173,10 @@ namespace FeedCenter // Clean up common invalid XML characters feedText = feedText.Replace(" ", " "); + // Find ampersands that aren't properly escaped and replace them with escaped versions + var r = new Regex("&(?!(?:[a-z]+|#[0-9]+|#x[0-9a-f]+);)"); + feedText = r.Replace(feedText, "&"); + return Tuple.Create(FeedReadResult.Success, feedText); } catch (IOException ioException)