You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NormalizeLineEndings(Mac) leaves a CRLF in the output and drops a line break when a CRLF is followed by an LF #137
The first pass turns every \r\n into \r. When a lone \n comes right after a \r\n, it then sits directly after the new \r. The second pass uses LineEndingRegexUnix ((?<!\r)\n), whose lookbehind rejects exactly that \n, so it is left alone. The two passes together build a new\r\n.
Repro
"a\r\n\nb".NormalizeLineEndings(LineEndingStyle.Mac)// returns "a\r\nb", expected "a\r\rb""a\r\n\nb".NormalizeLineEndings(LineEndingStyle.Mac).DetermineLineEndings()// Windows, not Mac
A local repro confirmed this: a\r\n\nb -> Mac: a\r\nb detect=Windows.
The other styles give correct results for the same input: Unix gives a\n\nb and Windows gives a\r\n\r\nb. Their pass order cannot create a new CRLF.
Why it matters
The output still contains a Windows line ending, so the result is not Mac-normalized, and DetermineLineEndings() on it reports Windows.
One of the two line breaks is lost, which changes the line count of the text.
A CRLF followed by an LF is common in files with mixed line endings, which is exactly the input a normalizer is for.
The existing NormalizeLineEndingsToMac test uses line1\nline2\r\nline3\r, which never puts an LF right after a CRLF, so it does not catch this.
Suggested fix
Do the conversion in one pass with a single alternation regex, so no intermediate string can create new sequences:
Priority: Medium. For mixed-ending input (CRLF followed by LF), which is exactly what a normalizer gets, NormalizeLineEndings(Mac) silently loses a line break and leaves a CRLF in the output. That changes the line count.
Area / suggested assignee:StringExtensions.NormalizeLineEndings (Extensions/StringExtensions.cs:208). Owner: @matt-edmondson
Activity
matt-edmondson commentedon Sep 27, 2026
Triage
NormalizeLineEndings(Mac)silently loses a line break and leaves a CRLF in the output. That changes the line count.StringExtensions.NormalizeLineEndings(Extensions/StringExtensions.cs:208). Owner: @matt-edmondsonConcurrentDictionary.GetOrCreate.\r\n|\r|\nalternation for every style, and add the CRLF+LF and CR+CRLF tests across allLineEndingStylevalues.Generated by Claude Code
Normalize line endings in one pass, so Mac keeps every break