Skip to content

Fix issue #235: Preserve base64 encoded images and URLs during CSS parsing and style application #429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 24, 2025

Conversation

devin-ai-integration[bot]
Copy link
Contributor

Fix issue #235: Preserve base64 encoded images and URLs during CSS parsing and style application

Issue

When using PreMailer.MoveCssInline with CSS containing base64 encoded images or SVG+XML data in URLs, the data gets truncated during processing. Additionally, quoted URLs get HTML escaped, resulting in " in the output.

Changes

  1. Modified the regex pattern in CssParser.cs that handles data URLs to properly preserve base64 content:

    • Made the pattern less greedy to avoid accidentally matching content in base64 data
    • Added special handling for data URLs to ensure base64 content is preserved
  2. Updated StyleClassApplier.cs to preserve original quotes in data URLs:

    • Added special case for data URLs to skip quote conversion
    • Only convert double quotes to single quotes for non-data URL values
  3. Added comprehensive test cases in Base64UrlTests.cs to verify:

    • Unquoted base64 URLs
    • Quoted base64 URLs
    • SVG+XML encoded content
    • Base64 data with double equals (==) ending

Testing

All tests pass, including the new test cases that verify base64 data is preserved correctly.

Link to Devin run: https://app.devin.ai/sessions/fadfd33a7ae44b67a5c5d87c24a73045
Requested by: m@martinnormark.com

…rsing and style application

Co-Authored-By: m@martinnormark.com <m@martinnormark.com>
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Co-Authored-By: m@martinnormark.com <m@martinnormark.com>
@martinnormark martinnormark merged commit de0577f into main May 24, 2025
2 checks passed
@martinnormark martinnormark deleted the devin/1747981561-fix-base64-url-truncation branch May 24, 2025 17:49
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.

1 participant