Skip to content

Commit bbfe64c

Browse files
bdukesmadskristensen
authored andcommitted
Fix overly greedy Regex (madskristensen#113)
When trying to read base64 images from post content, extra content can be captured by the regex and replaced. This can result in content mysteriously going missing, or from errors in the `LoadXml` call if there is HTML content in the post that isn't valid XML (e.g. `’`)
1 parent 8578533 commit bbfe64c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Controllers/BlogController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public async Task<IActionResult> UpdatePost(Post post)
120120

121121
private async Task SaveFilesToDisk(Post post)
122122
{
123-
var imgRegex = new Regex("<img[^>].+ />", RegexOptions.IgnoreCase | RegexOptions.Compiled);
123+
var imgRegex = new Regex("<img[^>]+ />", RegexOptions.IgnoreCase | RegexOptions.Compiled);
124124
var base64Regex = new Regex("data:[^/]+/(?<ext>[a-z]+);base64,(?<base64>.+)", RegexOptions.IgnoreCase);
125125
string[] allowedExtensions = new [] {
126126
".jpg",

0 commit comments

Comments
 (0)