Skip to content

Commit c48e1eb

Browse files
Fix various runtime null reference errors caused by bad data (#227)
* Convert relative path into absolute path. Check file exists and throw FileNotFoundException * Add null check
1 parent 34dd564 commit c48e1eb

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Solutions/Stacker.Cli/Formatters/ShortFormContentFormatter.cs

+12-9
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,22 @@ public IEnumerable<string> Format(string campaignMedium, string campaignName, IE
4848

4949
string title = item.Content.Title;
5050

51-
foreach (HashTag hashTag in item.HashTags.Where(x => !x.Default))
51+
if (item.HashTags is not null)
5252
{
53-
if (title.Contains(hashTag.Text, StringComparison.InvariantCultureIgnoreCase))
53+
foreach (HashTag hashTag in item.HashTags?.Where(x => !x.Default))
5454
{
55-
titleMatches.Add(hashTag);
56-
string pattern = $@"\b{Regex.Escape(hashTag.Text)}\b";
57-
title = Regex.Replace(title, pattern, hashTag.Tag, RegexOptions.IgnoreCase);
55+
if (title.Contains(hashTag.Text, StringComparison.InvariantCultureIgnoreCase))
56+
{
57+
titleMatches.Add(hashTag);
58+
string pattern = $@"\b{Regex.Escape(hashTag.Text)}\b";
59+
title = Regex.Replace(title, pattern, hashTag.Tag, RegexOptions.IgnoreCase);
60+
}
5861
}
59-
}
6062

61-
foreach (HashTag hashTag in titleMatches)
62-
{
63-
item.HashTags.Remove(hashTag);
63+
foreach (HashTag hashTag in titleMatches)
64+
{
65+
item.HashTags.Remove(hashTag);
66+
}
6467
}
6568

6669
content.Append(title);

0 commit comments

Comments
 (0)