-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Encode TargetPaths before writing them to the editorconfig (#16858)
* Encode TargetPaths before writing them to the editorconfig * Address feedback from peer review * Fix generated output paths in tests
- Loading branch information
1 parent
3560c4d
commit ad420ea
Showing
6 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
src/Assets/TestProjects/RazorSimpleMvc/Views/Home/#F{}i+l!e.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p>Just a file with a special character in the name!</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Numerics; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
|
||
namespace Microsoft.AspNetCore.Razor.Tasks | ||
{ | ||
// The compiler leverages .editorconfig files to transfer information between | ||
// msbuild and the compiler. However, the transfer of data from MSBuild to the | ||
// .editorconfig file to the source generator, causes a lot of issues as strings | ||
// are transferred from one type to another. For example, the editorconfig file | ||
// interprets "#" as comments and omits them from the produced AnalyzerConfigOptions. | ||
// Characters like {} in the filename cause issues with resolving the type. To work | ||
// around this, we encode everything before writing it to the editorconfig then decode | ||
// inside the Razor source generator. | ||
public class EncodeRazorInputItem : Task | ||
{ | ||
[Required] | ||
public ITaskItem[] RazorInputItems { get; set; } | ||
|
||
[Output] | ||
public ITaskItem[] EncodedRazorInputItems { get; set; } | ||
|
||
public override bool Execute() | ||
{ | ||
EncodedRazorInputItems = new ITaskItem[RazorInputItems.Length]; | ||
|
||
for (var i = 0; i < RazorInputItems.Length; i++) | ||
{ | ||
var input = RazorInputItems[i]; | ||
var targetPath = Convert.ToBase64String(Encoding.UTF8.GetBytes(input.GetMetadata("TargetPath"))); | ||
|
||
var outputItem = new TaskItem(input); | ||
outputItem.SetMetadata("TargetPath", targetPath); | ||
|
||
EncodedRazorInputItems[i] = outputItem; | ||
} | ||
|
||
return !Log.HasLoggedErrors; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters