|
3 | 3 |
|
4 | 4 | #nullable disable
|
5 | 5 |
|
| 6 | +using System.Text.Json; |
6 | 7 | using System.Text.RegularExpressions;
|
7 | 8 | using Microsoft.AspNetCore.StaticWebAssets.Tasks;
|
8 | 9 |
|
@@ -617,5 +618,72 @@ public void RegeneratingScopedCss_ForProjectWithReferences()
|
617 | 618 | text.Should().Contain("background-color: orangered");
|
618 | 619 | text.Should().MatchRegex(""".*@import '_content/ClassLibrary/ClassLibrary\.[a-zA-Z0-9]+\.bundle\.scp\.css.*""");
|
619 | 620 | }
|
| 621 | + |
| 622 | + [Fact] |
| 623 | + public void Build_GeneratesUrlEncodedLinkHeaderForNonAsciiProjectName() |
| 624 | + { |
| 625 | + var testAsset = "RazorAppWithPackageAndP2PReference"; |
| 626 | + ProjectDirectory = CreateAspNetSdkTestAsset(testAsset); |
| 627 | + |
| 628 | + // Rename the ClassLibrary project to have non-ASCII characters |
| 629 | + var originalLibPath = Path.Combine(ProjectDirectory.Path, "AnotherClassLib"); |
| 630 | + var newLibPath = Path.Combine(ProjectDirectory.Path, "项目"); |
| 631 | + Directory.Move(originalLibPath, newLibPath); |
| 632 | + |
| 633 | + // Update the project file to set the assembly name and package ID |
| 634 | + var libProjectFile = Path.Combine(newLibPath, "AnotherClassLib.csproj"); |
| 635 | + var newLibProjectFile = Path.Combine(newLibPath, "项目.csproj"); |
| 636 | + File.Move(libProjectFile, newLibProjectFile); |
| 637 | + |
| 638 | + // Add assembly name property to ensure consistent naming |
| 639 | + var libProjectContent = File.ReadAllText(newLibProjectFile); |
| 640 | + // Find the first PropertyGroup closing tag and replace it |
| 641 | + var targetPattern = "</PropertyGroup>"; |
| 642 | + var replacement = " <AssemblyName>项目</AssemblyName>\n <PackageId>项目</PackageId>\n </PropertyGroup>"; |
| 643 | + var index = libProjectContent.IndexOf(targetPattern); |
| 644 | + if (index >= 0) |
| 645 | + { |
| 646 | + libProjectContent = libProjectContent.Substring(0, index) + replacement + libProjectContent.Substring(index + targetPattern.Length); |
| 647 | + } |
| 648 | + File.WriteAllText(newLibProjectFile, libProjectContent); |
| 649 | + |
| 650 | + // Update the main project to reference the renamed library |
| 651 | + var mainProjectFile = Path.Combine(ProjectDirectory.Path, "AppWithPackageAndP2PReference", "AppWithPackageAndP2PReference.csproj"); |
| 652 | + var mainProjectContent = File.ReadAllText(mainProjectFile); |
| 653 | + mainProjectContent = mainProjectContent.Replace(@"..\AnotherClassLib\AnotherClassLib.csproj", @"..\项目\项目.csproj"); |
| 654 | + File.WriteAllText(mainProjectFile, mainProjectContent); |
| 655 | + |
| 656 | + // Ensure library has scoped CSS |
| 657 | + var libCssFile = Path.Combine(newLibPath, "Views", "Shared", "Index.cshtml.css"); |
| 658 | + if (!File.Exists(libCssFile)) |
| 659 | + { |
| 660 | + Directory.CreateDirectory(Path.GetDirectoryName(libCssFile)); |
| 661 | + File.WriteAllText(libCssFile, ".test { color: red; }"); |
| 662 | + } |
| 663 | + |
| 664 | + EnsureLocalPackagesExists(); |
| 665 | + |
| 666 | + var restore = CreateRestoreCommand(ProjectDirectory, "AppWithPackageAndP2PReference"); |
| 667 | + ExecuteCommand(restore).Should().Pass(); |
| 668 | + |
| 669 | + var build = CreateBuildCommand(ProjectDirectory, "AppWithPackageAndP2PReference"); |
| 670 | + ExecuteCommand(build).Should().Pass(); |
| 671 | + |
| 672 | + var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); |
| 673 | + |
| 674 | + // Check that the staticwebassets.build.endpoints.json file contains URL-encoded characters |
| 675 | + var endpointsFile = Path.Combine(intermediateOutputPath, "staticwebassets.build.endpoints.json"); |
| 676 | + new FileInfo(endpointsFile).Should().Exist(); |
| 677 | + |
| 678 | + var endpointsContent = File.ReadAllText(endpointsFile); |
| 679 | + var json = JsonSerializer.Deserialize<StaticWebAssetEndpointsManifest>(endpointsContent, new JsonSerializerOptions(JsonSerializerDefaults.Web)); |
| 680 | + |
| 681 | + var styles = json.Endpoints.Where(e => e.Route.EndsWith("styles.css")); |
| 682 | + |
| 683 | + foreach (var styleEndpoint in styles) |
| 684 | + { |
| 685 | + styleEndpoint.ResponseHeaders.Should().Contain(h => h.Name.Equals("Link", StringComparison.OrdinalIgnoreCase) && h.Value.Contains("%E9%A1%B9%E7%9B%AE")); |
| 686 | + } |
| 687 | + } |
620 | 688 | }
|
621 | 689 | }
|
0 commit comments