Skip to content

HRINT-4835-1 - missing /blog prefix#140

Merged
garayx merged 2 commits into
ayende:DOTNET8-MIGRATIONfrom
VladShpilMan:HRINT-4835-1
Jun 3, 2026
Merged

HRINT-4835-1 - missing /blog prefix#140
garayx merged 2 commits into
ayende:DOTNET8-MIGRATIONfrom
VladShpilMan:HRINT-4835-1

Conversation

@VladShpilMan

Copy link
Copy Markdown

Post: https://staging.ayende.com/blog/364/confirmed-microsoft-is-cleaning-windows

In RavenDB:
<img src="Images/ms-cleaning-windows.jpg" />

At render time, AutoMapper calls ImageUrlRewriter.RewriteImageUrls(), which rewrites the src:
"Images/ms-cleaning-windows.jpg" → "/blog/Images/ms-cleaning-windows.jpg"

The browser loads /blog/Images/ms-cleaning-windows.jpg → ImagesController → RavenDB → image.

I decided to fix this at render time to avoid modifying old data.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds render-time rewriting of <img src="..."> URLs in post HTML so legacy posts that reference Images/... (or older ayende.com/Blog/images/... URLs) are served correctly under the /blog/Images/... path without rewriting stored RavenDB data.

Changes:

  • Introduce ImageUrlRewriter that parses HTML and rewrites <img src> values to /blog/Images/... for recognized legacy patterns.
  • Apply the rewrite during AutoMapper mapping for both post details and post summaries.
  • Add xUnit coverage validating rewrite behavior for legacy/relative/absolute/external image URLs.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
RaccoonBlog.Web/Infrastructure/AutoMapper/Profiles/Resolvers/ImageUrlRewriter.cs Adds HTML parsing + <img src> rewriting logic to normalize legacy image URLs to /blog/Images/....
RaccoonBlog.Web/Infrastructure/AutoMapper/Profiles/PostViewModelMapperProfile.cs Applies image URL rewriting when mapping Post.Body for the post details view model.
RaccoonBlog.Web/Infrastructure/AutoMapper/Profiles/PostsViewModelMapperProfile.cs Applies image URL rewriting when mapping Post.Body for post summary view models.
RaccoonBlog.IntegrationTests/ImageUrlRewriterTests.cs Adds tests for the new rewrite behavior across several URL formats.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 21 to +23
.ForMember(x => x.Title, o => o.MapFrom(m => WebUtility.HtmlDecode(m.Title)))
.ForMember(x => x.Author, o => o.Ignore())
.ForMember(x => x.Body, o => o.MapFrom(m => new HtmlString(ImageUrlRewriter.RewriteImageUrls(m.Body))))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes much sense because we have if (string.IsNullOrEmpty(html))

Comment on lines 22 to 25
.ForMember(x => x.PublishedAt, o => o.MapFrom(m => m.PublishAt))
.ForMember(x=>x.Title, o => o.MapFrom(m => System.Net.WebUtility.HtmlDecode(m.Title)))
.ForMember(x => x.Body, o => o.MapFrom(m => m.Body))
.ForMember(x => x.Body, o => o.MapFrom(m => new HtmlString(ImageUrlRewriter.RewriteImageUrls(m.Body))))
.ForMember(x => x.IsSerie, o => o.MapFrom(m => m.Title.Contains(":")))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same.

@garayx garayx merged commit 1d8f08e into ayende:DOTNET8-MIGRATION Jun 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants