Skip to content

Commit 9368876

Browse files
Fix case-sensitive reserved word checks: use -cin instead of -in per Lua §3.1; add tests for capitalized identifiers (End, While)
1 parent d036c0f commit 9368876

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/functions/private/ConvertFrom-LuaTable.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
$varName = $script:luaString.Substring($identStart, $script:luaPos - $identStart)
115115

116116
# Lua grammar: variable names cannot be reserved words (§3.1)
117-
if ($varName -in $reservedWords) {
117+
if ($varName -cin $reservedWords) {
118118
if ($script:luaSkipValidation) {
119119
Write-Warning "Reserved word '$varName' used as a variable name at position $identStart."
120120
} else {

src/functions/private/Read-LuaTable.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
if ($script:luaPos -lt $script:luaString.Length -and
8888
$script:luaString[$script:luaPos] -eq '=') {
8989
# Lua grammar: Name cannot be a reserved word (§3.1)
90-
if ($ident -in $reservedWords) {
90+
if ($ident -cin $reservedWords) {
9191
if ($script:luaSkipValidation) {
9292
Write-Warning "Reserved word '$ident' used as a bare identifier key at position $identStart."
9393
} else {

tests/Lua.Tests.ps1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,17 @@ B = { val = 2 }
522522
$result['while'] | Should -Be 2
523523
}
524524

525+
It 'Allows capitalized reserved words as bare table keys (Lua keywords are case-sensitive)' {
526+
$result = ConvertFrom-Lua -InputObject '{ End = 1, While = "loop" }' -AsHashtable
527+
$result['End'] | Should -Be 1
528+
$result['While'] | Should -Be 'loop'
529+
}
530+
531+
It 'Allows capitalized reserved words as assignment variable names (Lua keywords are case-sensitive)' {
532+
$result = ConvertFrom-Lua -InputObject 'End = 1' -AsHashtable
533+
$result['End'] | Should -Be 1
534+
}
535+
525536
It 'Throws on reserved word as assignment variable name' {
526537
{ ConvertFrom-Lua -InputObject 'end = 1' } | Should -Throw '*Reserved word*'
527538
}

0 commit comments

Comments
 (0)