Make Razor file encoding consistent (#11530)
* Make Razor file encoding consistent * feedback
This commit is contained in:
parent
73a2603aa6
commit
f40bfde9ff
|
|
@ -1,4 +1,4 @@
|
||||||
<h3>Component1</h3>
|
<h3>Component1</h3>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@page
|
@page
|
||||||
@using Microsoft.AspNetCore.Identity
|
@using Microsoft.AspNetCore.Identity
|
||||||
@inject SignInManager<IdentityUser> SignInManager
|
@inject SignInManager<IdentityUser> SignInManager
|
||||||
@functions {
|
@functions {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@using Microsoft.AspNetCore.Identity
|
@using Microsoft.AspNetCore.Identity
|
||||||
@inject SignInManager<IdentityUser> SignInManager
|
@inject SignInManager<IdentityUser> SignInManager
|
||||||
@inject UserManager<IdentityUser> UserManager
|
@inject UserManager<IdentityUser> UserManager
|
||||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@page "/counter"
|
@page "/counter"
|
||||||
|
|
||||||
<h1>Counter</h1>
|
<h1>Counter</h1>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@page "/fetchdata"
|
@page "/fetchdata"
|
||||||
@using RazorComponentsWeb_CSharp.Data
|
@using RazorComponentsWeb_CSharp.Data
|
||||||
@inject WeatherForecastService ForecastService
|
@inject WeatherForecastService ForecastService
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@page "/"
|
@page "/"
|
||||||
@namespace RazorComponentsWeb_CSharp.Pages
|
@namespace RazorComponentsWeb_CSharp.Pages
|
||||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@using Microsoft.AspNetCore.Authentication.AzureADB2C.UI
|
@using Microsoft.AspNetCore.Authentication.AzureADB2C.UI
|
||||||
@using Microsoft.Extensions.Options
|
@using Microsoft.Extensions.Options
|
||||||
@inject IOptionsMonitor<AzureADB2COptions> AzureADB2COptions
|
@inject IOptionsMonitor<AzureADB2COptions> AzureADB2COptions
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<AuthorizeView>
|
<AuthorizeView>
|
||||||
<Authorized>
|
<Authorized>
|
||||||
<a href="Identity/Account/Manage">Hello, @context.User.Identity.Name!</a>
|
<a href="Identity/Account/Manage">Hello, @context.User.Identity.Name!</a>
|
||||||
<a href="Identity/Account/LogOut">Log out</a>
|
<a href="Identity/Account/LogOut">Log out</a>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<AuthorizeView>
|
<AuthorizeView>
|
||||||
<Authorized>
|
<Authorized>
|
||||||
Hello, @context.User.Identity.Name!
|
Hello, @context.User.Identity.Name!
|
||||||
<a href="AzureAD/Account/SignOut">Log out</a>
|
<a href="AzureAD/Account/SignOut">Log out</a>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
<AuthorizeView>
|
<AuthorizeView>
|
||||||
Hello, @context.User.Identity.Name!
|
Hello, @context.User.Identity.Name!
|
||||||
</AuthorizeView>
|
</AuthorizeView>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<div class="top-row pl-4 navbar navbar-dark">
|
<div class="top-row pl-4 navbar navbar-dark">
|
||||||
<a class="navbar-brand" href="">RazorComponentsWeb-CSharp</a>
|
<a class="navbar-brand" href="">RazorComponentsWeb-CSharp</a>
|
||||||
<button class="navbar-toggler" @onclick="@ToggleNavMenu">
|
<button class="navbar-toggler" @onclick="@ToggleNavMenu">
|
||||||
<span class="navbar-toggler-icon"></span>
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@using System.Net.Http
|
@using System.Net.Http
|
||||||
@using Microsoft.AspNetCore.Components.Forms
|
@using Microsoft.AspNetCore.Components.Forms
|
||||||
@using Microsoft.AspNetCore.Components.Layouts
|
@using Microsoft.AspNetCore.Components.Layouts
|
||||||
@using Microsoft.AspNetCore.Components.Routing
|
@using Microsoft.AspNetCore.Components.Routing
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@using Microsoft.AspNetCore.Identity
|
@using Microsoft.AspNetCore.Identity
|
||||||
@inject SignInManager<IdentityUser> SignInManager
|
@inject SignInManager<IdentityUser> SignInManager
|
||||||
@inject UserManager<IdentityUser> UserManager
|
@inject UserManager<IdentityUser> UserManager
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@*#if (IndividualB2CAuth)
|
@*#if (IndividualB2CAuth)
|
||||||
@using Microsoft.AspNetCore.Authentication.AzureADB2C.UI
|
@using Microsoft.AspNetCore.Authentication.AzureADB2C.UI
|
||||||
@using Microsoft.Extensions.Options
|
@using Microsoft.Extensions.Options
|
||||||
@inject IOptionsMonitor<AzureADB2COptions> AzureADB2COptions
|
@inject IOptionsMonitor<AzureADB2COptions> AzureADB2COptions
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
<script src="~/lib/jquery-validation/dist/jquery.validate.js"></script>
|
<script src="~/lib/jquery-validation/dist/jquery.validate.js"></script>
|
||||||
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
|
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@*#if (IndividualLocalAuth)
|
@*#if (IndividualLocalAuth)
|
||||||
@using Microsoft.AspNetCore.Identity
|
@using Microsoft.AspNetCore.Identity
|
||||||
#endif*@
|
#endif*@
|
||||||
@using Company.WebApplication1
|
@using Company.WebApplication1
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@using Microsoft.AspNetCore.Identity
|
@using Microsoft.AspNetCore.Identity
|
||||||
@inject SignInManager<IdentityUser> SignInManager
|
@inject SignInManager<IdentityUser> SignInManager
|
||||||
@inject UserManager<IdentityUser> UserManager
|
@inject UserManager<IdentityUser> UserManager
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@using System.Security.Principal
|
@using System.Security.Principal
|
||||||
@*#if (IndividualB2CAuth)
|
@*#if (IndividualB2CAuth)
|
||||||
@using Microsoft.AspNetCore.Authentication.AzureADB2C.UI
|
@using Microsoft.AspNetCore.Authentication.AzureADB2C.UI
|
||||||
@using Microsoft.Extensions.Options
|
@using Microsoft.Extensions.Options
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
<script src="~/lib/jquery-validation/dist/jquery.validate.js"></script>
|
<script src="~/lib/jquery-validation/dist/jquery.validate.js"></script>
|
||||||
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
|
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
|
|
@ -21,7 +22,7 @@ namespace Templates.Test
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("Web.ProjectTemplates")]
|
[InlineData("Web.ProjectTemplates")]
|
||||||
[InlineData("Web.Spa.ProjectTemplates")]
|
[InlineData("Web.Spa.ProjectTemplates")]
|
||||||
public void CheckForByteOrderMark_ForAllTemplates(string projectName)
|
public void JSAndJSONInAllTemplates_ShouldNotContainBOM(string projectName)
|
||||||
{
|
{
|
||||||
var currentDirectory = Directory.GetCurrentDirectory();
|
var currentDirectory = Directory.GetCurrentDirectory();
|
||||||
var projectTemplateDir = Directory.GetParent(currentDirectory).Parent.Parent.Parent.FullName;
|
var projectTemplateDir = Directory.GetParent(currentDirectory).Parent.Parent.Parent.FullName;
|
||||||
|
|
@ -36,7 +37,7 @@ namespace Templates.Test
|
||||||
foreach (var file in files)
|
foreach (var file in files)
|
||||||
{
|
{
|
||||||
var filePath = Path.GetFullPath(file);
|
var filePath = Path.GetFullPath(file);
|
||||||
var fileStream = new FileStream(filePath, FileMode.Open);
|
using var fileStream = new FileStream(filePath, FileMode.Open);
|
||||||
|
|
||||||
var bytes = new byte[3];
|
var bytes = new byte[3];
|
||||||
fileStream.Read(bytes, 0, 3);
|
fileStream.Read(bytes, 0, 3);
|
||||||
|
|
@ -58,5 +59,35 @@ namespace Templates.Test
|
||||||
|
|
||||||
Assert.False(filesWithBOMCharactersPresent);
|
Assert.False(filesWithBOMCharactersPresent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RazorFilesInWebProjects_ShouldContainBOM()
|
||||||
|
{
|
||||||
|
var projectName = "Web.ProjectTemplates";
|
||||||
|
var currentDirectory = Directory.GetCurrentDirectory();
|
||||||
|
var projectTemplateDir = Directory.GetParent(currentDirectory).Parent.Parent.Parent.FullName;
|
||||||
|
var path = Path.Combine(projectName, "content");
|
||||||
|
var directories = Directory.GetDirectories(Path.Combine(projectTemplateDir, path), "*Sharp");
|
||||||
|
|
||||||
|
foreach (var directory in directories)
|
||||||
|
{
|
||||||
|
var files = (IEnumerable<string>)Directory.GetFiles(directory, "*.cshtml", SearchOption.AllDirectories);
|
||||||
|
files = files.Concat(Directory.GetFiles(directory, "*.razor", SearchOption.AllDirectories));
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
var filePath = Path.GetFullPath(file);
|
||||||
|
using var fileStream = new FileStream(filePath, FileMode.Open);
|
||||||
|
|
||||||
|
var bytes = new byte[3];
|
||||||
|
fileStream.Read(bytes, 0, 3);
|
||||||
|
|
||||||
|
// Check for UTF8 BOM 0xEF,0xBB,0xBF
|
||||||
|
var expectedBytes = Encoding.UTF8.GetPreamble();
|
||||||
|
Assert.True(
|
||||||
|
bytes[0] == expectedBytes[0] && bytes[1] == expectedBytes[1] && bytes[2] == expectedBytes[2],
|
||||||
|
$"File {filePath} doesn't contains UTF-8 BOM characters.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue