Skip to content

Commit 29d4c14

Browse files
authored
Scrub user assets too... (#544)
* Update ContentScrubber.cs * Update ContentScrubber.cs * Update DotNet.DocsTools/Utility/ContentScrubber.cs
1 parent 11118a6 commit 29d4c14

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

DotNet.DocsTools/Utility/ContentScrubber.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ namespace DotNet.DocsTools.Utility;
44

55
public static partial class ContentScrubber
66
{
7-
private const string Replacement = "<i>Image link removed to protect against security vulnerability.</i>";
8-
7+
private const string ImgReplacement = "<i>Image link removed to protect against security vulnerability.</i>";
8+
private const string UserAssetReplacement = "<i>User asset removed to protect against security vulnerability.</i>";
9+
910
/// <summary>
1011
/// Remove false security vulnerabilities from the content.
1112
/// </summary>
@@ -22,9 +23,24 @@ public static partial class ContentScrubber
2223
/// </remarks>
2324
public static string ScrubContent(this string content)
2425
{
25-
return ImageAnchorRegEx().Replace(content, Replacement);
26+
var postImageReplacementContent = ImageAnchorRegEx().Replace(content, ImgReplacement);
27+
if (content != postImageReplacementContent)
28+
{
29+
Console.WriteLine("Replaced linked image in content.");
30+
}
31+
32+
var postUserAttachementReplacementContent = AttachmentAnchorRegEx().Replace(postImageReplacementContent, UserAssetReplacement);
33+
if (postImageReplacementContent != postUserAttachementReplacementContent)
34+
{
35+
Console.WriteLine("Replaced linked user asset in content.");
36+
}
37+
38+
return postUserAttachementReplacementContent;
2639
}
2740

2841
[GeneratedRegex("""<a.+href="https:\/\/private-user-images\.githubusercontent\.com\/.+".+><\/a>""")]
2942
private static partial Regex ImageAnchorRegEx();
43+
44+
[GeneratedRegex("""<a.+href="https:\/\/github\.com\/user-attachments\/assets\/.+".+><\/a>""")]
45+
private static partial Regex AttachmentAnchorRegEx();
3046
}

0 commit comments

Comments
 (0)