From 72cc18c1a654d2c080fd6a6a58dd34efa9e52aad Mon Sep 17 00:00:00 2001 From: Simone Bizzotto Date: Wed, 19 Jun 2019 23:20:42 +0200 Subject: [PATCH] Invoke-DbatoolsFormatter, fix #5790 (#5791) --- functions/Invoke-DbatoolsFormatter.ps1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/functions/Invoke-DbatoolsFormatter.ps1 b/functions/Invoke-DbatoolsFormatter.ps1 index d58e7dc541..a5681edb5e 100644 --- a/functions/Invoke-DbatoolsFormatter.ps1 +++ b/functions/Invoke-DbatoolsFormatter.ps1 @@ -45,6 +45,10 @@ function Invoke-DbatoolsFormatter { $CBHRex = [regex]'(?smi)\s+<#[^#]*#>' $CBHStartRex = [regex]'(?[ ]+)<#' $CBHEndRex = [regex]'(?[ ]*)#>' + $OSEOL = "`n" + if ($psVersionTable.Platform -ne 'Unix') { + $OSEOL = "`r`n" + } } process { if (Test-FunctionInterrupt) { return } @@ -57,7 +61,7 @@ function Invoke-DbatoolsFormatter { $content = Get-Content -Path $realPath -Raw -Encoding UTF8 #strip ending empty lines - $content = $content -replace "(?s)`r`n\s*$" + $content = $content -replace "(?s)$OSEOL\s*$" try { $content = Invoke-Formatter -ScriptDefinition $content -Settings CodeFormattingOTBS -ErrorAction Stop } catch { @@ -83,7 +87,7 @@ function Invoke-DbatoolsFormatter { foreach ($line in $content.Split("`n")) { $realContent += $line.TrimEnd() } - [System.IO.File]::WriteAllText($realPath, ($realContent -Join "`r`n"), $Utf8NoBomEncoding) + [System.IO.File]::WriteAllText($realPath, ($realContent -Join "$OSEOL"), $Utf8NoBomEncoding) } } } \ No newline at end of file