Issue #2779 - Normalize newlines to "\r\n" instead of "\n".

This commit is contained in:
sornaks 2015-08-14 13:14:47 -07:00
parent e73e73acdd
commit 27f7f3d437
8 changed files with 53 additions and 60 deletions

View File

@ -131,31 +131,31 @@ namespace Microsoft.AspNet.Mvc.Razor
documentAbsoluteIndex: 7,
documentLineIndex: 0,
documentCharacterIndex: 7,
generatedAbsoluteIndex: 432,
generatedAbsoluteIndex: 444,
generatedLineIndex: 12,
generatedCharacterIndex: 7,
contentLength: 8),
BuildLineMapping(
documentAbsoluteIndex: 31,
documentAbsoluteIndex: 33,
documentLineIndex: 2,
documentCharacterIndex: 14,
generatedAbsoluteIndex: 798,
generatedAbsoluteIndex: 823,
generatedLineIndex: 25,
generatedCharacterIndex: 14,
contentLength: 85),
BuildLineMapping(
documentAbsoluteIndex: 135,
documentAbsoluteIndex: 139,
documentLineIndex: 4,
documentCharacterIndex: 17,
generatedAbsoluteIndex: 2258,
generatedAbsoluteIndex: 2313,
generatedLineIndex: 55,
generatedCharacterIndex: 95,
contentLength: 3),
BuildLineMapping(
documentAbsoluteIndex: 161,
documentAbsoluteIndex: 166,
documentLineIndex: 5,
documentCharacterIndex: 18,
generatedAbsoluteIndex: 2565,
generatedAbsoluteIndex: 2626,
generatedLineIndex: 61,
generatedCharacterIndex: 87,
contentLength: 5),
@ -200,15 +200,15 @@ namespace Microsoft.AspNet.Mvc.Razor
documentAbsoluteIndex: 13,
documentLineIndex: 0,
documentCharacterIndex: 13,
generatedAbsoluteIndex: 1237,
generatedAbsoluteIndex: 1269,
generatedLineIndex: 32,
generatedCharacterIndex: 13,
contentLength: 4),
BuildLineMapping(
documentAbsoluteIndex: 41,
documentAbsoluteIndex: 43,
documentLineIndex: 2,
documentCharacterIndex: 5,
generatedAbsoluteIndex: 1316,
generatedAbsoluteIndex: 1353,
generatedLineIndex: 37,
generatedCharacterIndex: 6,
contentLength: 21),
@ -234,15 +234,15 @@ namespace Microsoft.AspNet.Mvc.Razor
documentAbsoluteIndex: 1,
documentLineIndex: 0,
documentCharacterIndex: 1,
generatedAbsoluteIndex: 56,
generatedAbsoluteIndex: 59,
generatedLineIndex: 3,
generatedCharacterIndex: 0,
contentLength: 17),
BuildLineMapping(
documentAbsoluteIndex: 27,
documentAbsoluteIndex: 28,
documentLineIndex: 1,
documentCharacterIndex: 8,
generatedAbsoluteIndex: 680,
generatedAbsoluteIndex: 706,
generatedLineIndex: 26,
generatedCharacterIndex: 8,
contentLength: 20),
@ -268,23 +268,23 @@ namespace Microsoft.AspNet.Mvc.Razor
documentAbsoluteIndex: 7,
documentLineIndex: 0,
documentCharacterIndex: 7,
generatedAbsoluteIndex: 208,
generatedAbsoluteIndex: 214,
generatedLineIndex: 6,
generatedCharacterIndex: 7,
contentLength: 7),
BuildLineMapping(
documentAbsoluteIndex: 23,
documentAbsoluteIndex: 24,
documentLineIndex: 1,
documentCharacterIndex: 8,
generatedAbsoluteIndex: 705,
generatedAbsoluteIndex: 731,
generatedLineIndex: 26,
generatedCharacterIndex: 8,
contentLength: 20),
BuildLineMapping(
documentAbsoluteIndex: 52,
documentAbsoluteIndex: 54,
documentLineIndex: 2,
documentCharacterIndex: 8,
generatedAbsoluteIndex: 923,
generatedAbsoluteIndex: 957,
generatedLineIndex: 34,
generatedCharacterIndex: 8,
contentLength: 23),
@ -310,39 +310,39 @@ namespace Microsoft.AspNet.Mvc.Razor
documentAbsoluteIndex: 7,
documentLineIndex: 0,
documentCharacterIndex: 7,
generatedAbsoluteIndex: 216,
generatedAbsoluteIndex: 222,
generatedLineIndex: 6,
generatedCharacterIndex: 7,
contentLength: 7),
BuildLineMapping(
documentAbsoluteIndex: 23,
documentAbsoluteIndex: 24,
documentLineIndex: 1,
documentCharacterIndex: 8,
generatedAbsoluteIndex: 721,
generatedAbsoluteIndex: 747,
generatedLineIndex: 26,
generatedCharacterIndex: 8,
contentLength: 20),
BuildLineMapping(
documentAbsoluteIndex: 56,
documentAbsoluteIndex: 58,
documentLineIndex: 2,
documentCharacterIndex: 8,
generatedAbsoluteIndex: 943,
generatedAbsoluteIndex: 977,
generatedLineIndex: 34,
generatedCharacterIndex: 8,
contentLength: 23),
BuildLineMapping(
documentAbsoluteIndex: 90,
documentAbsoluteIndex: 93,
documentLineIndex: 3,
documentCharacterIndex: 8,
generatedAbsoluteIndex: 1168,
generatedAbsoluteIndex: 1210,
generatedLineIndex: 42,
generatedCharacterIndex: 8,
contentLength: 21),
BuildLineMapping(
documentAbsoluteIndex: 125,
documentAbsoluteIndex: 129,
documentLineIndex: 4,
documentCharacterIndex: 8,
generatedAbsoluteIndex: 1391,
generatedAbsoluteIndex: 1441,
generatedLineIndex: 50,
generatedCharacterIndex: 8,
contentLength: 24),
@ -364,7 +364,7 @@ namespace Microsoft.AspNet.Mvc.Razor
host.NamespaceImports.Clear();
var expectedLineMappings = new[]
{
BuildLineMapping(7, 0, 7, 188, 6, 7, 30),
BuildLineMapping(7, 0, 7, 194, 6, 7, 30),
};
// Act and Assert
@ -536,7 +536,7 @@ namespace Microsoft.AspNet.Mvc.Razor
// We normalize newlines so no matter what platform we're on
// they're consistent (for code generation tests).
var codeWriter = base.CreateCodeWriter();
codeWriter.NewLine = "\n";
codeWriter.NewLine = "\r\n";
return codeWriter;
}

View File

@ -1,4 +1,4 @@
#pragma checksum "TestFiles/Input/Basic.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "4901c9b2325c62315b9048c930cac987201ccbab"
#pragma checksum "TestFiles/Input/Basic.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "54a70ff4c6d27ac6cdc6725cb6bab12012015729"
namespace Asp
{
using System;
@ -34,18 +34,18 @@ namespace Asp
EndContext();
WriteAttribute("class", Tuple.Create(" class=\"", 4), Tuple.Create("\"", 17),
Tuple.Create(Tuple.Create("", 12), Tuple.Create<System.Object, System.Int32>(logo, 12), false));
BeginContext(18, 22, true);
WriteLiteral(">\n Hello world\n ");
BeginContext(18, 24, true);
WriteLiteral(">\r\n Hello world\r\n ");
EndContext();
BeginContext(41, 21, false);
BeginContext(43, 21, false);
#line 3 "TestFiles/Input/Basic.cshtml"
Write(Html.Input("SomeKey"));
#line default
#line hidden
EndContext();
BeginContext(62, 7, true);
WriteLiteral("\n</div>");
BeginContext(64, 8, true);
WriteLiteral("\r\n</div>");
EndContext();
}
#pragma warning restore 1998

View File

@ -1,4 +1,4 @@
#pragma checksum "TestFiles/Input/Inject.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "1b6d0816c4801cc45d2f51f612298d2e978b8dac"
#pragma checksum "TestFiles/Input/Inject.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "225760ec3beca02a80469066fab66433e90ddc2e"
namespace Asp
{
#line 1 "TestFiles/Input/Inject.cshtml"

View File

@ -1,4 +1,4 @@
#pragma checksum "TestFiles/Input/InjectWithModel.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "a3c84d50826508cf6aab272b5b403b41f22eb058"
#pragma checksum "TestFiles/Input/InjectWithModel.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "1f010500f93116162444110956e512df61642f4e"
namespace Asp
{
using System;

View File

@ -1,4 +1,4 @@
#pragma checksum "TestFiles/Input/InjectWithSemicolon.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "76a79c64a24a4b239eaa7f70aa9a708c5794e050"
#pragma checksum "TestFiles/Input/InjectWithSemicolon.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "fc807ec0dc76610bdca62f482fefd7f584348df9"
namespace Asp
{
using System;

View File

@ -1,4 +1,4 @@
#pragma checksum "TestFiles/Input/Model.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "dbb4c96d18dd379f760a081c6ff84ed9fd31b82b"
#pragma checksum "TestFiles/Input/Model.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "31c5b047a450ac9f6dc4116626667d26bfb657ba"
namespace Asp
{
using System;

View File

@ -1,4 +1,4 @@
#pragma checksum "TestFiles/Input/ModelExpressionTagHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "a866c3c5622349399a04557339d06e12178fb260"
#pragma checksum "TestFiles/Input/ModelExpressionTagHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "fd1207a6d248f0e3aeabecaa338dca0ffb99d10d"
namespace Asp
{
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
@ -45,8 +45,8 @@ namespace Asp
public override async Task ExecuteAsync()
{
__tagHelperRunner = __tagHelperRunner ?? new Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperRunner();
BeginContext(117, 1, true);
WriteLiteral("\n");
BeginContext(120, 2, true);
WriteLiteral("\r\n");
EndContext();
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("input-test", TagMode.SelfClosing, "test", async() => {
}
@ -60,12 +60,12 @@ __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For = CreateModelExpression(__mo
#line hidden
__tagHelperExecutionContext.AddTagHelperAttribute("for", __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For);
__tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
BeginContext(118, 24, false);
BeginContext(122, 24, false);
await WriteTagHelperAsync(__tagHelperExecutionContext);
EndContext();
__tagHelperExecutionContext = __tagHelperScopeManager.End();
BeginContext(142, 1, true);
WriteLiteral("\n");
BeginContext(146, 2, true);
WriteLiteral("\r\n");
EndContext();
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("input-test", TagMode.SelfClosing, "test", async() => {
}
@ -79,7 +79,7 @@ __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For = CreateModelExpression(__mo
#line hidden
__tagHelperExecutionContext.AddTagHelperAttribute("for", __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For);
__tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
BeginContext(143, 27, false);
BeginContext(148, 27, false);
await WriteTagHelperAsync(__tagHelperExecutionContext);
EndContext();
__tagHelperExecutionContext = __tagHelperScopeManager.End();

View File

@ -66,16 +66,13 @@ namespace Microsoft.AspNet.Mvc
var stream = assembly.GetManifestResourceStream(fullName);
if (sourceFile)
{
// Normalize line endings to '\n' (LF). This removes core.autocrlf, core.eol, core.safecrlf, and
// .gitattributes from the equation and treats "\r\n", "\r", and "\n" as equivalent. Does not handle
// some obscure line endings (e.g. "\n\r") but otherwise ensures checksums and line mappings are
// consistent.
// Normalize line endings to '\r\n' (CRLF). This removes core.autocrlf, core.eol, core.safecrlf, and
// .gitattributes from the equation and treats "\r\n" and "\n" as equivalent. Does not handle
// some line endings like "\r" but otherwise ensures checksums and line mappings are consistent.
string text;
using (var streamReader = new StreamReader(stream))
{
text = streamReader.ReadToEnd()
.Replace("\r\n", "\n") // Windows line endings
.Replace("\r", "\n"); // Older Mac OS line endings
text = streamReader.ReadToEnd().Replace("\r", "").Replace("\n", "\r\n");
}
var bytes = Encoding.UTF8.GetBytes(text);
@ -186,14 +183,10 @@ namespace Microsoft.AspNet.Mvc
[Conditional("GENERATE_BASELINES")]
public static void UpdateFile(Assembly assembly, string resourceName, string previousContent, string content)
{
// Normalize line endings to '\n' for comparison. This removes Environment.NewLine from the equation. Not
// Normalize line endings to '\r\n' for comparison. This removes Environment.NewLine from the equation. Not
// worth updating files just because we generate baselines on a different system.
var normalizedPreviousContent = previousContent
?.Replace("\r\n", "\n")
.Replace("\r", "\n");
var normalizedContent = content
.Replace("\r\n", "\n")
.Replace("\r", "\n");
var normalizedPreviousContent = previousContent?.Replace("\r", "").Replace("\n", "\r\n");
var normalizedContent = content.Replace("\r", "").Replace("\n", "\r\n");
if (!string.Equals(normalizedPreviousContent, normalizedContent, StringComparison.Ordinal))
{