Skip to content

Commit 7923add

Browse files
Address PR review feedback
1 parent 05714e5 commit 7923add

4 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/functions/private/Format-LuaKey.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@
3232
$escaped = $Key `
3333
-replace '\\', '\\' `
3434
-replace '"', '\"' `
35+
-replace "`0", '\0' `
36+
-replace "`a", '\a' `
3537
-replace "`n", '\n' `
3638
-replace "`r", '\r' `
3739
-replace "`t", '\t' `
40+
-replace "`v", '\v' `
3841
-replace "`b", '\b' `
3942
-replace "`f", '\f'
4043
return "[`"$escaped`"]"

src/functions/private/Read-LuaTable.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@
122122
if ($script:luaPos -lt $script:luaString.Length -and
123123
$script:luaString[$script:luaPos] -eq '}') {
124124
$script:luaPos++ # skip }
125+
} else {
126+
$script:luaCurrentDepth--
127+
throw "Unterminated Lua table constructor. Expected '}' before end of input."
125128
}
126129

127130
$script:luaCurrentDepth--

src/functions/public/Lua/ConvertFrom-Lua.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
process {
8686
$result = ConvertFrom-LuaTable -InputString $InputObject -AsPSCustomObject:(-not $AsHashtable) -MaxDepth $Depth
8787
if ($NoEnumerate -and $result -is [System.Array]) {
88-
Write-Output -NoEnumerate $result
88+
Write-Output -InputObject $result -NoEnumerate
8989
} else {
9090
$result
9191
}

tests/Lua.Tests.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,10 @@ B = { val = 2 }
476476
It 'Throws on unterminated multi-line string' {
477477
{ ConvertFrom-Lua -InputObject '[[hello' } | Should -Throw '*Unterminated*'
478478
}
479+
480+
It 'Throws on unterminated table (missing closing brace)' {
481+
{ ConvertFrom-Lua -InputObject '{ a = 1' } | Should -Throw '*Unterminated*'
482+
}
479483
}
480484

481485
Context 'Pipeline input' {
@@ -879,6 +883,12 @@ Describe 'ConvertTo-Lua' {
879883
$result = ConvertTo-Lua -InputObject @{ 'while' = 'loop' } -Compress
880884
$result | Should -Be '{["while"]="loop"}'
881885
}
886+
887+
It 'Escapes control characters in bracket-quoted keys' {
888+
$key = "line1`nline2"
889+
$result = ConvertTo-Lua -InputObject @{ $key = 'value' } -Compress
890+
$result | Should -Be '{["line1\nline2"]="value"}'
891+
}
882892
}
883893

884894
Context 'PSCustomObject' {

0 commit comments

Comments
 (0)