Skip to content

[Blazor] Fix JSInitializer URL computation for base URLs with query parameters #63185

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot 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.

Copy link
Contributor

Greetings human! You've submitted a PR that modifies code that is shared with https://github.com/dotnet/runtime . Please make sure you synchronize this code with the changes in that repo!

@Copilot 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 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 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 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 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

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