File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7979 return $InputObject.ToString ([System.Globalization.CultureInfo ]::InvariantCulture)
8080 }
8181
82- if ($InputObject -is [float ] -or $InputObject -is [double ] -or
83- $InputObject -is [decimal ] -or $InputObject -is [single ]) {
82+ if ($InputObject -is [double ]) {
83+ if ([double ]::IsNaN($InputObject ) -or [double ]::IsInfinity($InputObject )) {
84+ throw " Cannot serialize non-finite double value '$InputObject ' to Lua. Lua numeric literals do not support NaN or Infinity."
85+ }
86+ return $InputObject.ToString ([System.Globalization.CultureInfo ]::InvariantCulture)
87+ }
88+
89+ if ($InputObject -is [float ] -or $InputObject -is [single ]) {
90+ if ([single ]::IsNaN($InputObject ) -or [single ]::IsInfinity($InputObject )) {
91+ throw " Cannot serialize non-finite single value '$InputObject ' to Lua. Lua numeric literals do not support NaN or Infinity."
92+ }
93+ return $InputObject.ToString ([System.Globalization.CultureInfo ]::InvariantCulture)
94+ }
95+
96+ if ($InputObject -is [decimal ]) {
8497 return $InputObject.ToString ([System.Globalization.CultureInfo ]::InvariantCulture)
8598 }
8699
155168 }
156169
157170 # Handle PSCustomObject
158- if ($InputObject -is [psobject ]) {
171+ if ($InputObject -is [System.Management.Automation.PSCustomObject ]) {
159172 $properties = $InputObject.PSObject.Properties | Where-Object { $_.MemberType -eq ' NoteProperty' }
160173 if (-not $properties ) {
161174 return ' {}'
Original file line number Diff line number Diff line change 1616 - [int] / [long] -> Lua integer
1717 - [float] / [double] -> Lua float
1818 - [bool] -> Lua boolean (true/false)
19- - $null -> omitted ( nil means absent in Lua)
19+ - $null -> top-level input serializes as nil; null-valued properties/keys are omitted
2020
2121 . EXAMPLE
2222 ```powershell
Original file line number Diff line number Diff line change @@ -973,6 +973,35 @@ Describe 'ConvertTo-Lua' {
973973 $result | Should - Be ' {x=10}'
974974 }
975975 }
976+
977+ Context ' Non-finite float values' {
978+ It ' Throws on NaN double' {
979+ { ConvertTo-Lua - InputObject ([double ]::NaN) } | Should - Throw ' *NaN*'
980+ }
981+
982+ It ' Throws on Infinity double' {
983+ { ConvertTo-Lua - InputObject ([double ]::PositiveInfinity) } | Should - Throw ' *Infinity*'
984+ }
985+
986+ It ' Throws on negative Infinity double' {
987+ { ConvertTo-Lua - InputObject ([double ]::NegativeInfinity) } | Should - Throw ' *Infinity*'
988+ }
989+ }
990+
991+ Context ' .NET object string fallback' {
992+ It ' Serializes DateTime as string instead of empty table' {
993+ $result = ConvertTo-Lua - InputObject ([datetime ]' 2026-01-01' ) - Compress
994+ $result | Should -Not - Be ' {}'
995+ $result | Should -Match ' ^".*"$'
996+ }
997+
998+ It ' Serializes Guid as string instead of empty table' {
999+ $guid = [guid ]::NewGuid()
1000+ $result = ConvertTo-Lua - InputObject $guid - Compress
1001+ $result | Should -Not - Be ' {}'
1002+ $result | Should -Match ' ^".*"$'
1003+ }
1004+ }
9761005}
9771006
9781007Describe ' Round-trip conversion' {
You can’t perform that action at this time.
0 commit comments