Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 27, 2025

URL-encode scoped CSS Link headers for non-ASCII project names

Description

Blazor apps with non-ASCII project names (e.g. 中文) failed at runtime due to raw non-ASCII characters in generated Link headers for scoped CSS bundles.

Fixes #51038

Customer Impact

This is required to be compliant with GB18030 and deal with cases where project names use non-ascii characters.

Regression?

  • Yes
  • No

9.0

Risk

  • High
  • Medium
  • Low

Updates the manifest generation logic to ensure we URL encode path segments on the Link header. No other header that we emit needs this treatment.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

Copilot AI changed the title [WIP] [ASP.NET] Scoped CSS should URL encode the link header Fix scoped CSS URL encoding for non-ASCII project names Sep 27, 2025
Copilot AI requested a review from javiercn September 27, 2025 11:33
Copilot finished work on behalf of javiercn September 27, 2025 11:33
Copy link
Member

@javiercn javiercn left a comment

Choose a reason for hiding this comment

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

@copilot address the feedback and make sure you don't modify unrelated files.

Copy link
Member

Choose a reason for hiding this comment

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

Unrelated change. Undo

Copy link
Contributor Author

Copilot AI commented Sep 27, 2025

@copilot address the feedback and make sure you don't modify unrelated files.

Addressed feedback in commit 9e13d45:

  • Reverted unnecessary RelativePath URL encoding changes (lines 235-241)
  • Reverted all unrelated test file formatting changes
  • Updated test to use proper RazorAppWithPackageAndP2PReference structure with library dependency named "项目"
  • Only the Link header value is now URL-encoded as requested

Copilot AI requested a review from javiercn September 27, 2025 12:46
Copilot finished work on behalf of javiercn September 27, 2025 12:46
@javiercn javiercn marked this pull request as ready for review September 27, 2025 18:30
@javiercn
Copy link
Member

There seems to be this unrelated test failure that seems to be failing pretty consistently Microsoft.NET.Publish.Tests.GivenThatWeWantToPublishAnAotApp.Microsoft.NET.Publish.Tests.GivenThatWeWantToPublishAnAotApp.NativeAot_hw_fails_with_unsupported_host_rid(targetFramework: "net10.0")

Copy link
Member

@ilonatommy ilonatommy left a comment

Choose a reason for hiding this comment

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

Tested with dogfood sdk script and blazor app.

@javiercn javiercn changed the title Fix scoped CSS URL encoding for non-ASCII project names URL-encode scoped CSS Link headers for non-ASCII project names Sep 29, 2025
@ilonatommy
Copy link
Member

ilonatommy commented Sep 29, 2025

All failures are marked as known build errors but build analysis does not want to get green.

@ilonatommy
Copy link
Member

/ba-g build analysis should be green, all failures are known

Copilot AI and others added 2 commits September 30, 2025 11:52
…ct names

Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
Copilot AI and others added 4 commits September 30, 2025 11:52
…er project structure

Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
@javiercn javiercn force-pushed the copilot/fix-43cc9698-4150-4c8c-a307-ed00dbbcd48e branch from 69393b7 to 95dcef5 Compare September 30, 2025 09:52
@lewing lewing added this to the 10.0.1xx milestone Sep 30, 2025
@lewing lewing changed the title URL-encode scoped CSS Link headers for non-ASCII project names [release/10.0.1xx] URL-encode scoped CSS Link headers for non-ASCII project names Sep 30, 2025
@lewing
Copy link
Member

lewing commented Oct 1, 2025

approved in email

{
var index = header.IndexOf('<');
if (index == -1)
{
Copy link
Member

Choose a reason for hiding this comment

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

nit, better to make this index < 0

index++;
var endIndex = header.IndexOf('>', index);
if (endIndex == -1)
{
Copy link
Member

Choose a reason for hiding this comment

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

similar

@lewing lewing enabled auto-merge (squash) October 1, 2025 22:48
@lewing lewing merged commit 95d125e into release/10.0.1xx Oct 2, 2025
26 of 27 checks passed
@lewing lewing deleted the copilot/fix-43cc9698-4150-4c8c-a307-ed00dbbcd48e branch October 2, 2025 00:16
YuliiaKovalova pushed a commit to dotnet/msbuild that referenced this pull request Nov 20, 2025
…st (#12572)

Resolves #12571

This PR adds `System.Uri::EscapeDataString` (and `UnescapeDataString`)
to the MSBuild property function allowlist, enabling developers to
properly escape URI components in MSBuild projects without needing to
resort to workarounds with `UriBuilder.Path`.

## Problem

Previously, developers who needed to URL-encode strings in MSBuild had
to use workarounds like manipulating `UriBuilder.Path`, which is not
semantically correct and error-prone. The `System.Uri::EscapeDataString`
method is the standard .NET approach for encoding URI data components.

## Solution

Added `System.Uri` to the `AvailableStaticMethods` allowlist in
`Constants.cs`, which enables all static methods on the `System.Uri`
class including `EscapeDataString` and `UnescapeDataString`.

## Usage

```xml
<PropertyGroup>
  <QueryParam>hello world &amp; test=123</QueryParam>
  <EscapedParam>$([System.Uri]::EscapeDataString($(QueryParam)))</EscapedParam>
  <!-- Result: hello%20world%20%26%20test%3D123 -->
</PropertyGroup>
```

## Safety

`System.Uri::EscapeDataString` is a pure function with no side effects,
making it completely safe for use during project evaluation. It follows
the same security model as other allowed static methods like
`System.String` and `System.Convert`.

## Testing

- Added comprehensive unit test verifying the functionality works
correctly
- Verified round-trip encoding/decoding with various input types
- Confirmed all existing tests continue to pass (27/27 intrinsic
function tests)
- Validated that existing `UriBuilder` functionality remains unaffected

This change provides a clean, semantically correct way to handle URI
encoding in MSBuild without breaking any existing functionality.

<!-- START COPILOT CODING AGENT SUFFIX -->



<details>

<summary>Original prompt</summary>

> 
> ----
> 
> *This section details on the original issue you should resolve*
> 
> <issue_title>Instead of hacking with UriBuilder.Path, I think it would
be better to add `[System.Uri]::EscapeDataString` to the allowlist at
the MSBuild side.</issue_title>
> <issue_description>Instead of hacking with UriBuilder.Path, I think it
would be better to add `[System.Uri]::EscapeDataString` to the allowlist
at the MSBuild side.
> 
> _Originally posted by @KalleOlaviNiemitalo in
dotnet/sdk#51039 (comment)
> 
> We should allow this method on the set of known functions. It's
available across framework and modern .NET. </issue_description>
> 
> ## Comments on the Issue (you are @copilot in this section)
> 
> <comments>
> </comments>
> 


</details>
Fixes #12571

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants