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, documentAbsoluteIndex: 7,
documentLineIndex: 0, documentLineIndex: 0,
documentCharacterIndex: 7, documentCharacterIndex: 7,
generatedAbsoluteIndex: 432, generatedAbsoluteIndex: 444,
generatedLineIndex: 12, generatedLineIndex: 12,
generatedCharacterIndex: 7, generatedCharacterIndex: 7,
contentLength: 8), contentLength: 8),
BuildLineMapping( BuildLineMapping(
documentAbsoluteIndex: 31, documentAbsoluteIndex: 33,
documentLineIndex: 2, documentLineIndex: 2,
documentCharacterIndex: 14, documentCharacterIndex: 14,
generatedAbsoluteIndex: 798, generatedAbsoluteIndex: 823,
generatedLineIndex: 25, generatedLineIndex: 25,
generatedCharacterIndex: 14, generatedCharacterIndex: 14,
contentLength: 85), contentLength: 85),
BuildLineMapping( BuildLineMapping(
documentAbsoluteIndex: 135, documentAbsoluteIndex: 139,
documentLineIndex: 4, documentLineIndex: 4,
documentCharacterIndex: 17, documentCharacterIndex: 17,
generatedAbsoluteIndex: 2258, generatedAbsoluteIndex: 2313,
generatedLineIndex: 55, generatedLineIndex: 55,
generatedCharacterIndex: 95, generatedCharacterIndex: 95,
contentLength: 3), contentLength: 3),
BuildLineMapping( BuildLineMapping(
documentAbsoluteIndex: 161, documentAbsoluteIndex: 166,
documentLineIndex: 5, documentLineIndex: 5,
documentCharacterIndex: 18, documentCharacterIndex: 18,
generatedAbsoluteIndex: 2565, generatedAbsoluteIndex: 2626,
generatedLineIndex: 61, generatedLineIndex: 61,
generatedCharacterIndex: 87, generatedCharacterIndex: 87,
contentLength: 5), contentLength: 5),
@ -200,15 +200,15 @@ namespace Microsoft.AspNet.Mvc.Razor
documentAbsoluteIndex: 13, documentAbsoluteIndex: 13,
documentLineIndex: 0, documentLineIndex: 0,
documentCharacterIndex: 13, documentCharacterIndex: 13,
generatedAbsoluteIndex: 1237, generatedAbsoluteIndex: 1269,
generatedLineIndex: 32, generatedLineIndex: 32,
generatedCharacterIndex: 13, generatedCharacterIndex: 13,
contentLength: 4), contentLength: 4),
BuildLineMapping( BuildLineMapping(
documentAbsoluteIndex: 41, documentAbsoluteIndex: 43,
documentLineIndex: 2, documentLineIndex: 2,
documentCharacterIndex: 5, documentCharacterIndex: 5,
generatedAbsoluteIndex: 1316, generatedAbsoluteIndex: 1353,
generatedLineIndex: 37, generatedLineIndex: 37,
generatedCharacterIndex: 6, generatedCharacterIndex: 6,
contentLength: 21), contentLength: 21),
@ -234,15 +234,15 @@ namespace Microsoft.AspNet.Mvc.Razor
documentAbsoluteIndex: 1, documentAbsoluteIndex: 1,
documentLineIndex: 0, documentLineIndex: 0,
documentCharacterIndex: 1, documentCharacterIndex: 1,
generatedAbsoluteIndex: 56, generatedAbsoluteIndex: 59,
generatedLineIndex: 3, generatedLineIndex: 3,
generatedCharacterIndex: 0, generatedCharacterIndex: 0,
contentLength: 17), contentLength: 17),
BuildLineMapping( BuildLineMapping(
documentAbsoluteIndex: 27, documentAbsoluteIndex: 28,
documentLineIndex: 1, documentLineIndex: 1,
documentCharacterIndex: 8, documentCharacterIndex: 8,
generatedAbsoluteIndex: 680, generatedAbsoluteIndex: 706,
generatedLineIndex: 26, generatedLineIndex: 26,
generatedCharacterIndex: 8, generatedCharacterIndex: 8,
contentLength: 20), contentLength: 20),
@ -268,23 +268,23 @@ namespace Microsoft.AspNet.Mvc.Razor
documentAbsoluteIndex: 7, documentAbsoluteIndex: 7,
documentLineIndex: 0, documentLineIndex: 0,
documentCharacterIndex: 7, documentCharacterIndex: 7,
generatedAbsoluteIndex: 208, generatedAbsoluteIndex: 214,
generatedLineIndex: 6, generatedLineIndex: 6,
generatedCharacterIndex: 7, generatedCharacterIndex: 7,
contentLength: 7), contentLength: 7),
BuildLineMapping( BuildLineMapping(
documentAbsoluteIndex: 23, documentAbsoluteIndex: 24,
documentLineIndex: 1, documentLineIndex: 1,
documentCharacterIndex: 8, documentCharacterIndex: 8,
generatedAbsoluteIndex: 705, generatedAbsoluteIndex: 731,
generatedLineIndex: 26, generatedLineIndex: 26,
generatedCharacterIndex: 8, generatedCharacterIndex: 8,
contentLength: 20), contentLength: 20),
BuildLineMapping( BuildLineMapping(
documentAbsoluteIndex: 52, documentAbsoluteIndex: 54,
documentLineIndex: 2, documentLineIndex: 2,
documentCharacterIndex: 8, documentCharacterIndex: 8,
generatedAbsoluteIndex: 923, generatedAbsoluteIndex: 957,
generatedLineIndex: 34, generatedLineIndex: 34,
generatedCharacterIndex: 8, generatedCharacterIndex: 8,
contentLength: 23), contentLength: 23),
@ -310,39 +310,39 @@ namespace Microsoft.AspNet.Mvc.Razor
documentAbsoluteIndex: 7, documentAbsoluteIndex: 7,
documentLineIndex: 0, documentLineIndex: 0,
documentCharacterIndex: 7, documentCharacterIndex: 7,
generatedAbsoluteIndex: 216, generatedAbsoluteIndex: 222,
generatedLineIndex: 6, generatedLineIndex: 6,
generatedCharacterIndex: 7, generatedCharacterIndex: 7,
contentLength: 7), contentLength: 7),
BuildLineMapping( BuildLineMapping(
documentAbsoluteIndex: 23, documentAbsoluteIndex: 24,
documentLineIndex: 1, documentLineIndex: 1,
documentCharacterIndex: 8, documentCharacterIndex: 8,
generatedAbsoluteIndex: 721, generatedAbsoluteIndex: 747,
generatedLineIndex: 26, generatedLineIndex: 26,
generatedCharacterIndex: 8, generatedCharacterIndex: 8,
contentLength: 20), contentLength: 20),
BuildLineMapping( BuildLineMapping(
documentAbsoluteIndex: 56, documentAbsoluteIndex: 58,
documentLineIndex: 2, documentLineIndex: 2,
documentCharacterIndex: 8, documentCharacterIndex: 8,
generatedAbsoluteIndex: 943, generatedAbsoluteIndex: 977,
generatedLineIndex: 34, generatedLineIndex: 34,
generatedCharacterIndex: 8, generatedCharacterIndex: 8,
contentLength: 23), contentLength: 23),
BuildLineMapping( BuildLineMapping(
documentAbsoluteIndex: 90, documentAbsoluteIndex: 93,
documentLineIndex: 3, documentLineIndex: 3,
documentCharacterIndex: 8, documentCharacterIndex: 8,
generatedAbsoluteIndex: 1168, generatedAbsoluteIndex: 1210,
generatedLineIndex: 42, generatedLineIndex: 42,
generatedCharacterIndex: 8, generatedCharacterIndex: 8,
contentLength: 21), contentLength: 21),
BuildLineMapping( BuildLineMapping(
documentAbsoluteIndex: 125, documentAbsoluteIndex: 129,
documentLineIndex: 4, documentLineIndex: 4,
documentCharacterIndex: 8, documentCharacterIndex: 8,
generatedAbsoluteIndex: 1391, generatedAbsoluteIndex: 1441,
generatedLineIndex: 50, generatedLineIndex: 50,
generatedCharacterIndex: 8, generatedCharacterIndex: 8,
contentLength: 24), contentLength: 24),
@ -364,7 +364,7 @@ namespace Microsoft.AspNet.Mvc.Razor
host.NamespaceImports.Clear(); host.NamespaceImports.Clear();
var expectedLineMappings = new[] var expectedLineMappings = new[]
{ {
BuildLineMapping(7, 0, 7, 188, 6, 7, 30), BuildLineMapping(7, 0, 7, 194, 6, 7, 30),
}; };
// Act and Assert // Act and Assert
@ -536,7 +536,7 @@ namespace Microsoft.AspNet.Mvc.Razor
// We normalize newlines so no matter what platform we're on // We normalize newlines so no matter what platform we're on
// they're consistent (for code generation tests). // they're consistent (for code generation tests).
var codeWriter = base.CreateCodeWriter(); var codeWriter = base.CreateCodeWriter();
codeWriter.NewLine = "\n"; codeWriter.NewLine = "\r\n";
return codeWriter; 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 namespace Asp
{ {
using System; using System;
@ -34,18 +34,18 @@ namespace Asp
EndContext(); EndContext();
WriteAttribute("class", Tuple.Create(" class=\"", 4), Tuple.Create("\"", 17), WriteAttribute("class", Tuple.Create(" class=\"", 4), Tuple.Create("\"", 17),
Tuple.Create(Tuple.Create("", 12), Tuple.Create<System.Object, System.Int32>(logo, 12), false)); Tuple.Create(Tuple.Create("", 12), Tuple.Create<System.Object, System.Int32>(logo, 12), false));
BeginContext(18, 22, true); BeginContext(18, 24, true);
WriteLiteral(">\n Hello world\n "); WriteLiteral(">\r\n Hello world\r\n ");
EndContext(); EndContext();
BeginContext(41, 21, false); BeginContext(43, 21, false);
#line 3 "TestFiles/Input/Basic.cshtml" #line 3 "TestFiles/Input/Basic.cshtml"
Write(Html.Input("SomeKey")); Write(Html.Input("SomeKey"));
#line default #line default
#line hidden #line hidden
EndContext(); EndContext();
BeginContext(62, 7, true); BeginContext(64, 8, true);
WriteLiteral("\n</div>"); WriteLiteral("\r\n</div>");
EndContext(); EndContext();
} }
#pragma warning restore 1998 #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 namespace Asp
{ {
#line 1 "TestFiles/Input/Inject.cshtml" #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 namespace Asp
{ {
using System; 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 namespace Asp
{ {
using System; 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 namespace Asp
{ {
using System; 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 namespace Asp
{ {
using Microsoft.AspNet.Razor.Runtime.TagHelpers; using Microsoft.AspNet.Razor.Runtime.TagHelpers;
@ -45,8 +45,8 @@ namespace Asp
public override async Task ExecuteAsync() public override async Task ExecuteAsync()
{ {
__tagHelperRunner = __tagHelperRunner ?? new Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperRunner(); __tagHelperRunner = __tagHelperRunner ?? new Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperRunner();
BeginContext(117, 1, true); BeginContext(120, 2, true);
WriteLiteral("\n"); WriteLiteral("\r\n");
EndContext(); EndContext();
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("input-test", TagMode.SelfClosing, "test", async() => { __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input-test", TagMode.SelfClosing, "test", async() => {
} }
@ -60,12 +60,12 @@ __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For = CreateModelExpression(__mo
#line hidden #line hidden
__tagHelperExecutionContext.AddTagHelperAttribute("for", __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For); __tagHelperExecutionContext.AddTagHelperAttribute("for", __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For);
__tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
BeginContext(118, 24, false); BeginContext(122, 24, false);
await WriteTagHelperAsync(__tagHelperExecutionContext); await WriteTagHelperAsync(__tagHelperExecutionContext);
EndContext(); EndContext();
__tagHelperExecutionContext = __tagHelperScopeManager.End(); __tagHelperExecutionContext = __tagHelperScopeManager.End();
BeginContext(142, 1, true); BeginContext(146, 2, true);
WriteLiteral("\n"); WriteLiteral("\r\n");
EndContext(); EndContext();
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("input-test", TagMode.SelfClosing, "test", async() => { __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input-test", TagMode.SelfClosing, "test", async() => {
} }
@ -79,7 +79,7 @@ __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For = CreateModelExpression(__mo
#line hidden #line hidden
__tagHelperExecutionContext.AddTagHelperAttribute("for", __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For); __tagHelperExecutionContext.AddTagHelperAttribute("for", __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For);
__tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
BeginContext(143, 27, false); BeginContext(148, 27, false);
await WriteTagHelperAsync(__tagHelperExecutionContext); await WriteTagHelperAsync(__tagHelperExecutionContext);
EndContext(); EndContext();
__tagHelperExecutionContext = __tagHelperScopeManager.End(); __tagHelperExecutionContext = __tagHelperScopeManager.End();

View File

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