RickStrahl / Westwind.RazorHosting

Hosting the Razor Runtime outside of ASP.NET/MVC for use in non-Web .NET applications.
144 stars 32 forks source link

There is a error when processing a template with LF line separator. #17

Closed mlershov closed 6 years ago

mlershov commented 6 years ago

Hello! There is a error when processing a template with LF line separator (\n instead of \r\n ).

Method RazorEngine.FixupTemplate can be changed:

            int at = template.IndexOf("@model ");
            int at2 = template.IndexOf("\r\n", at);
            // Added by me
            if (at2 == -1)
            {
                at2 = template.IndexOf("\n", at);
            }
RickStrahl commented 6 years ago

The easier fix here is probably to just look for \n - The .Trim() in the model class parsing should remove the \r.

int at = template.IndexOf("@model ");
int at2 = template.IndexOf("\n", at);
var line = template.Substring(at, at2 - at);
var modelClass = line.Replace("@model ", "").Trim();