Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 8, 2025

The JSInitializer adjustPath function was using string concatenation to build URLs, which created malformed URLs when the document base URI contained query parameters or other URL components.

Problem:
When document.baseURI is http://domain?a=x, the string concatenation approach would create:

http://domain?a=x/_content/PackageId/file.js

This is a malformed URL with the path incorrectly placed after the query string.

Solution:
Replace string concatenation with the URL constructor, following the same pattern used in MonoPlatform.ts:

// Before (problematic)
path = base.endsWith('/') ? `${base}${path}` : `${base}/${path}`;

// After (fixed)
return new URL(path, document.baseURI).toString();

Result:
The same scenario now correctly produces:

http://domain/_content/PackageId/file.js

This change ensures proper URL resolution according to web standards, where query parameters and fragments in the base URL are handled correctly when resolving relative paths.

Added comprehensive tests covering various URL scenarios including query parameters, fragments, trailing slashes, and subdirectories.

Fixes #63184.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] [Blazor] Incorrectly computed URL for JSInitializers without base URL Fix JSInitializer URL computation for base URLs with query parameters Aug 8, 2025
Copilot AI requested a review from maraf August 8, 2025 12:08
Copilot finished work on behalf of maraf August 8, 2025 12:08
Copilot AI requested a review from javiercn August 8, 2025 13:44
Copilot finished work on behalf of javiercn August 8, 2025 13:44
@maraf maraf added area-blazor Includes: Blazor, Razor Components and removed Attention: Shared Code Modified labels Aug 9, 2025
@maraf maraf added this to the 10.0-rc1 milestone Aug 9, 2025
@maraf maraf changed the title Fix JSInitializer URL computation for base URLs with query parameters [Blazor] Fix JSInitializer URL computation for base URLs with query parameters Aug 9, 2025
@maraf maraf marked this pull request as ready for review August 9, 2025 11:21
Copilot AI review requested due to automatic review settings August 9, 2025 11:21
@maraf maraf requested a review from a team as a code owner August 9, 2025 11:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a URL resolution bug in the JSInitializer's adjustPath function where string concatenation was creating malformed URLs when the document base URI contained query parameters or other URL components.

Key changes:

  • Replaced string concatenation with the URL constructor for proper URL resolution
  • Aligned implementation with the pattern used in MonoPlatform.ts
  • Added comprehensive test coverage for various URL scenarios

@maraf maraf merged commit 58c3b48 into main Aug 11, 2025
29 checks passed
@maraf maraf deleted the copilot/fix-63184 branch August 11, 2025 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Blazor] Incorrectly computed URL for JSInitializers without base URL

3 participants