Skip to content

Commit 7242d0c

Browse files
Enhance error handling in Read-LuaString and Read-LuaTable; validate escape sequences and ensure table keys are not nil
1 parent 2cc5a98 commit 7242d0c

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

src/functions/private/Read-LuaString.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373
$hexStr = $script:luaString.Substring(
7474
$script:luaPos, 2
7575
)
76+
if ($hexStr -notmatch '^[0-9a-fA-F]{2}$') {
77+
throw 'Invalid \x escape sequence: expected two hexadecimal digits.'
78+
}
7679
$hexVal = [Convert]::ToInt32($hexStr, 16)
7780
$null = $result.Append([char]$hexVal)
7881
$script:luaPos += 2
@@ -91,6 +94,9 @@
9194
$script:luaString[$script:luaPos] -ne '}') {
9295
$script:luaPos++
9396
}
97+
if ($script:luaPos -ge $script:luaString.Length) {
98+
throw 'Invalid \u escape sequence: missing closing brace.'
99+
}
94100
$hexStr = $script:luaString.Substring(
95101
$hexStart,
96102
$script:luaPos - $hexStart

src/functions/private/Read-LuaTable.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
$script:luaPos++ # skip [
4545
Skip-LuaWhitespace
4646
$key = Read-LuaValue
47+
if ($null -eq $key) {
48+
throw 'Lua table keys cannot be nil.'
49+
}
4750
Skip-LuaWhitespace
4851
if ($script:luaPos -ge $script:luaString.Length -or
4952
$script:luaString[$script:luaPos] -ne ']') {

0 commit comments

Comments
 (0)