Make Razor file encoding consistent (#11530)

* Make Razor file encoding consistent

* feedback
This commit is contained in:
Ajay Bhargav Baaskaran 2019-06-25 15:51:20 -07:00 committed by GitHub
parent 73a2603aa6
commit f40bfde9ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 53 additions and 22 deletions

View File

@ -1,4 +1,4 @@
<h3>Component1</h3>
<h3>Component1</h3>
@code {

View File

@ -1,4 +1,4 @@
@page
@page
@using Microsoft.AspNetCore.Identity
@inject SignInManager<IdentityUser> SignInManager
@functions {

View File

@ -1,4 +1,4 @@
@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.Identity
@inject SignInManager<IdentityUser> SignInManager
@inject UserManager<IdentityUser> UserManager
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

View File

@ -1,4 +1,4 @@
@page "/counter"
@page "/counter"
<h1>Counter</h1>

View File

@ -1,4 +1,4 @@
@page "/fetchdata"
@page "/fetchdata"
@using RazorComponentsWeb_CSharp.Data
@inject WeatherForecastService ForecastService

View File

@ -1,4 +1,4 @@
@page "/"
@page "/"
@namespace RazorComponentsWeb_CSharp.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

View File

@ -1,4 +1,4 @@
@using Microsoft.AspNetCore.Authentication.AzureADB2C.UI
@using Microsoft.AspNetCore.Authentication.AzureADB2C.UI
@using Microsoft.Extensions.Options
@inject IOptionsMonitor<AzureADB2COptions> AzureADB2COptions

View File

@ -1,4 +1,4 @@
<AuthorizeView>
<AuthorizeView>
<Authorized>
<a href="Identity/Account/Manage">Hello, @context.User.Identity.Name!</a>
<a href="Identity/Account/LogOut">Log out</a>

View File

@ -1,4 +1,4 @@
<AuthorizeView>
<AuthorizeView>
<Authorized>
Hello, @context.User.Identity.Name!
<a href="AzureAD/Account/SignOut">Log out</a>

View File

@ -1,3 +1,3 @@
<AuthorizeView>
<AuthorizeView>
Hello, @context.User.Identity.Name!
</AuthorizeView>

View File

@ -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>
<button class="navbar-toggler" @onclick="@ToggleNavMenu">
<span class="navbar-toggler-icon"></span>

View File

@ -1,4 +1,4 @@
@using System.Net.Http
@using System.Net.Http
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Layouts
@using Microsoft.AspNetCore.Components.Routing

View File

@ -1,4 +1,4 @@
@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.Identity
@inject SignInManager<IdentityUser> SignInManager
@inject UserManager<IdentityUser> UserManager

View File

@ -1,4 +1,4 @@
@*#if (IndividualB2CAuth)
@*#if (IndividualB2CAuth)
@using Microsoft.AspNetCore.Authentication.AzureADB2C.UI
@using Microsoft.Extensions.Options
@inject IOptionsMonitor<AzureADB2COptions> AzureADB2COptions

View File

@ -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>

View File

@ -1,4 +1,4 @@
@*#if (IndividualLocalAuth)
@*#if (IndividualLocalAuth)
@using Microsoft.AspNetCore.Identity
#endif*@
@using Company.WebApplication1

View File

@ -1,4 +1,4 @@
@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.Identity
@inject SignInManager<IdentityUser> SignInManager
@inject UserManager<IdentityUser> UserManager

View File

@ -1,4 +1,4 @@
@using System.Security.Principal
@using System.Security.Principal
@*#if (IndividualB2CAuth)
@using Microsoft.AspNetCore.Authentication.AzureADB2C.UI
@using Microsoft.Extensions.Options

View File

@ -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>

View File

@ -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.
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Xunit;
using Xunit.Abstractions;
@ -21,7 +22,7 @@ namespace Templates.Test
[Theory]
[InlineData("Web.ProjectTemplates")]
[InlineData("Web.Spa.ProjectTemplates")]
public void CheckForByteOrderMark_ForAllTemplates(string projectName)
public void JSAndJSONInAllTemplates_ShouldNotContainBOM(string projectName)
{
var currentDirectory = Directory.GetCurrentDirectory();
var projectTemplateDir = Directory.GetParent(currentDirectory).Parent.Parent.Parent.FullName;
@ -36,7 +37,7 @@ namespace Templates.Test
foreach (var file in files)
{
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];
fileStream.Read(bytes, 0, 3);
@ -58,5 +59,35 @@ namespace Templates.Test
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.");
}
}
}
}
}