From 47b18e02bc431b3a6dba1f34b1ac33a46d000e0a Mon Sep 17 00:00:00 2001 From: Szeraax <6242511+Szeraax@users.noreply.github.com> Date: Tue, 12 May 2026 13:20:59 -0700 Subject: [PATCH] fix: #383 --- Turtle.psm1 | 5 +++++ Turtle.tests.ps1 | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/Turtle.psm1 b/Turtle.psm1 index 41a1efb..9f6bc54 100644 --- a/Turtle.psm1 +++ b/Turtle.psm1 @@ -10,6 +10,11 @@ $commandsPath = Join-Path $PSScriptRoot Commands . $file.FullName } +if ($global:OFS -ne ' ') { + Write-Warning "Turtle requires `$OFS to be a single space for SVG serialization. Setting `$global:OFS to ' '." + $global:OFS = ' ' +} + $myModule = $MyInvocation.MyCommand.ScriptBlock.Module $ExecutionContext.SessionState.PSVariable.Set($myModule.Name, $myModule) $myModule.pstypenames.insert(0, $myModule.Name) diff --git a/Turtle.tests.ps1 b/Turtle.tests.ps1 index bd8eb22..d6ee175 100644 --- a/Turtle.tests.ps1 +++ b/Turtle.tests.ps1 @@ -87,5 +87,32 @@ describe Turtle { } } } + + context 'Turtle OFS compatibility' { + it 'Warns and sets global OFS when imported with a custom global OFS' { + $originalOFS = $global:OFS + try { + Remove-Module Turtle -ErrorAction Ignore + $global:OFS = '|||' + + $importOutput = & { + Import-Module (Join-Path $PSScriptRoot 'Turtle.psd1') -Force + } 3>&1 + $importWarnings = @($importOutput | Where-Object { $_ -is [Management.Automation.WarningRecord] }) + + ($importWarnings.Message -join "`n") | Should -Match 'Setting \$global:OFS' + $global:OFS | Should -Be ' ' + + $svg = (turtle square 10).SVG.OuterXml + $svg | Should -Not -Match '\|\|\|' + $svg | Should -Match 'viewBox=.0 0 ' + } + finally { + $global:OFS = $originalOFS + Remove-Module Turtle -ErrorAction Ignore + Import-Module (Join-Path $PSScriptRoot 'Turtle.psd1') -Force | Out-Null + } + } + } }