forked from dotnet/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #465 from smadala/to-utf-8
Change encoding of template files from us-ascii to utf-8
- Loading branch information
Showing
16 changed files
with
161 additions
and
15 deletions.
There are no files selected for viewing
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
2 changes: 1 addition & 1 deletion
2
src/Templates/ProjectTemplates/CSharp/.NETCore/CSharpClassLibrary/ClassLibrary.vstemplate
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
2 changes: 1 addition & 1 deletion
2
...s/ProjectTemplates/CSharp/.NETCore/CSharpConsoleApplication/ConsoleApplication.vstemplate
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
2 changes: 1 addition & 1 deletion
2
src/Templates/ProjectTemplates/CSharp/.NETCore/CSharpUnitTest/UnitTest.vstemplate
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
2 changes: 1 addition & 1 deletion
2
src/Templates/ProjectTemplates/CSharp/.NETCore/CSharpUnitTest/UnitTest1.cs
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using System; | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace $safeprojectname$ | ||
|
2 changes: 1 addition & 1 deletion
2
src/Templates/ProjectTemplates/CSharp/.NETCore/CSharpXUnitTest/UnitTest1.cs
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using System; | ||
using System; | ||
using Xunit; | ||
|
||
namespace $safeprojectname$ | ||
|
2 changes: 1 addition & 1 deletion
2
src/Templates/ProjectTemplates/CSharp/.NETCore/CSharpXUnitTest/XUnitTest.vstemplate
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
2 changes: 1 addition & 1 deletion
2
...rojectTemplates/CSharp/.NETStandard/CSharpNetStandardClassLibrary/ClassLibrary.vstemplate
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
2 changes: 1 addition & 1 deletion
2
...tes/ProjectTemplates/VisualBasic/.NETCore/VisualBasicClassLibrary/ClassLibrary.vstemplate
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
2 changes: 1 addition & 1 deletion
2
...emplates/VisualBasic/.NETCore/VisualBasicConsoleApplication/ConsoleApplication.vstemplate
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
2 changes: 1 addition & 1 deletion
2
...lates/VisualBasic/.NETStandard/VisualBasicNetStandardClassLibrary/ClassLibrary.vstemplate
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,70 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.IO; | ||
using Xunit; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Templates.UnitTests | ||
{ | ||
public class EncodeTests | ||
{ | ||
private static readonly HashSet<string> IgnoreFileExtensionSet = new HashSet<string> {".json", ".props", ".target", ".png"}; | ||
|
||
[Fact] | ||
public void AllFilesInTemplatesShouldBeUTF8Encoded() | ||
{ | ||
var dirPath = Path.Combine(AppContext.BaseDirectory, @"..\..\..\src\Templates"); | ||
this.CheckAllFilesUTF8Encoded(dirPath); | ||
} | ||
|
||
private void CheckAllFilesUTF8Encoded(string dirPath) | ||
{ | ||
foreach (var filePath in Directory.GetFiles(dirPath)) | ||
{ | ||
var fileExtension = Path.GetExtension(filePath); | ||
if (EncodeTests.IgnoreFileExtensionSet.Contains(fileExtension)) | ||
{ | ||
continue; | ||
} | ||
Assert.True(this.IsUTF8EncodedWithBOM(filePath), $"{filePath} should be UTF-8 encoded with BOM"); | ||
} | ||
|
||
foreach (var childDirPath in Directory.GetDirectories(dirPath)) | ||
{ | ||
this.CheckAllFilesUTF8Encoded(childDirPath); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Check file is UTF-8 encoded with BOM. | ||
/// </summary> | ||
/// <param name="filePath"></param> | ||
/// <returns>true; If file encoding is UTF-8 with BOM</returns> | ||
private bool IsUTF8EncodedWithBOM(string filePath) | ||
{ | ||
var strictUTF8 = new UTF8Encoding(encoderShouldEmitUTF8Identifier: true, throwOnInvalidBytes: true); | ||
using (var reader = new StreamReader(File.OpenRead(filePath), strictUTF8, detectEncodingFromByteOrderMarks: false)) | ||
{ | ||
try | ||
{ | ||
reader.ReadToEnd(); | ||
} | ||
catch (DecoderFallbackException) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
var bom = new byte[3]; | ||
using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read)) | ||
{ | ||
file.Read(bom, 0, 3); | ||
} | ||
|
||
return bom[0] == 0xEF && bom[1] == 0xBB && bom[2] == 0xBF; | ||
} | ||
} | ||
} |
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,10 @@ | ||
{ | ||
"profiles": { | ||
"Templates.UnitTests": { | ||
"commandName": "Executable", | ||
"executablePath": "$(RunCommand)", | ||
"commandLineArgs": "\"$(OutDir)xunit.console.netcore.exe\" \"$(OutDir)$(AssemblyName).dll\" -wait", | ||
"workingDirectory": "$(OutDir)" | ||
} | ||
} | ||
} |
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,47 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), 'Common.props'))\Common.props" /> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion> | ||
<ProjectGuid>{7A328A78-533E-43F8-9AF8-9332A3331418}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<DefaultLanguage>en-US</DefaultLanguage> | ||
<TargetFramework>netstandard1.6</TargetFramework> | ||
<PackageTargetFallback>dotnet5.4;portable-net451+win8</PackageTargetFallback> | ||
<OutDir>$(OutDir)Tests\</OutDir> | ||
<GenerateDependencyFile>false</GenerateDependencyFile> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
<NonShipping>true</NonShipping> | ||
<StartAction>Program</StartAction> | ||
<StartProgram>$(DotNetTool).exe</StartProgram> | ||
<StartArguments>"$(OutDir)xunit.console.netcore.exe" "$(OutDir)$(AssemblyName).dll" -xml "$(OutDir)TemplatesTestResults.xml" -wait</StartArguments> | ||
<StartWorkingDirectory>$(OutDir)</StartWorkingDirectory> | ||
<DebugEngines>{2E36F1D4-B23C-435D-AB41-18E608940038}</DebugEngines> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Sdk"> | ||
<Version>$(SdkStage0Version)</Version> | ||
<PrivateAssets>All</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.DotNet.Cli.Utils"> | ||
<Version>$(DotNetCliUtilsVersion)</Version> | ||
</PackageReference> | ||
<PackageReference Include="FluentAssertions"> | ||
<Version>$(FluentAssertionsVersion)</Version> | ||
</PackageReference> | ||
<PackageReference Include="System.Diagnostics.FileVersionInfo"> | ||
<Version>4.0.0</Version> | ||
</PackageReference> | ||
<PackageReference Include="xunit"> | ||
<Version>$(xunitVersion)</Version> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="**\*.cs" Exclude="$(GlobalExclude)" /> | ||
<EmbeddedResource Include="**\*.resx" Exclude="$(GlobalExclude)" /> | ||
</ItemGroup> | ||
<Import Project="..\..\build\Targets\Templates.Imports.targets" /> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |