Skip to content

Commit

Permalink
Fix overly greedy Regex (madskristensen#113)
Browse files Browse the repository at this point in the history
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. `’`)
  • Loading branch information
bdukes authored and madskristensen committed Jul 26, 2019
1 parent 8578533 commit bbfe64c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Controllers/BlogController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public async Task<IActionResult> UpdatePost(Post post)

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

0 comments on commit bbfe64c

Please sign in to comment.