Skip to content

Fix port number preservation in CSS import URI resolution#432

Merged
martinnormark merged 1 commit intomainfrom
devin/1750958434-fix-port-number-uri-issue
Jun 26, 2025
Merged

Fix port number preservation in CSS import URI resolution#432
martinnormark merged 1 commit intomainfrom
devin/1750958434-fix-port-number-uri-issue

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Jun 26, 2025

Fix port number preservation in CSS import URI resolution

Summary

Fixes issue #431 where port numbers were being discarded from URIs when resolving relative CSS imports since version 2.7.0. The bug was in the GetBaseUri() method in ImportRuleCssSource.cs, which explicitly set Port = -1 to exclude port numbers when creating base URIs for resolving relative imports.

Changes:

  • Removed the Port = -1 assignment in ImportRuleCssSource.GetBaseUri() to preserve port numbers
  • Added comprehensive test ItShould_PreservePortNumber_WhenResolvingRelativeImports() to verify the fix

Impact: This enables CSS imports to work correctly when the base stylesheet is served from a non-standard port (e.g., development servers on localhost:8080).

Review & Testing Checklist for Human

  • Verify the test demonstrates the actual bug - Run the new test against the original code (before the fix) to confirm it fails
  • Test with real CSS imports and port numbers - Set up a development server on a non-standard port and verify CSS imports work end-to-end
  • Investigate original intent - Check git history/documentation to understand why port numbers were originally stripped - there may have been a legitimate reason

Diagram

graph TD
    A[PreMailer.cs] --> B[LinkTagCssSource.cs]
    B --> C[ImportRuleCssSource.cs]:::major-edit
    C --> D[GetBaseUri method]:::major-edit
    D --> E[UriBuilder construction]
    
    F[ImportRuleCssSourceTests.cs]:::major-edit --> G[New port preservation test]:::major-edit
    
    H[CSS with @import] --> C
    C --> I[WebDownloader.DownloadString]
    
    subgraph Legend
        L1[Major Edit]:::major-edit
        L2[Minor Edit]:::minor-edit  
        L3[Context/No Edit]:::context
    end
    
    classDef major-edit fill:#90EE90
    classDef minor-edit fill:#87CEEB
    classDef context fill:#FFFFFF
Loading

Notes

  • All 173 existing tests pass, indicating no regressions in current test coverage
  • The fix is minimal and focused - only removes the problematic line that strips port numbers
  • The new test follows existing patterns in the test suite using Mock
  • This change specifically affects relative CSS import resolution, not absolute URLs

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

- Add test to verify port numbers are preserved when resolving relative CSS imports
- Remove Port = -1 assignment in GetBaseUri() method that was stripping port numbers
- Fixes issue #431 where URIs with port numbers became inaccessible since version 2.7.0

Co-Authored-By: Martin <m@martinnormark.com>
@devin-ai-integration
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

@martinnormark martinnormark merged commit 73e3b31 into main Jun 26, 2025
2 checks passed
@martinnormark martinnormark deleted the devin/1750958434-fix-port-number-uri-issue branch June 26, 2025 17:57
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