Skip to content

v1.0.1

Latest

Choose a tag to compare

@github-actions github-actions released this 29 Apr 10:54
d532ebf

🩹 [Patch]: Reserved words in Lua input now detected with option to skip validation (#6)

ConvertFrom-Lua now validates that bare identifier keys and variable names are not Lua reserved words, throwing a clear error by default. A new -SkipValidation switch allows lenient import of out-of-spec data, emitting per-occurrence warnings instead. Enum string serialization no longer double-escapes backslashes.

  • Fixes #5

Changed: Reserved word validation on deserialization

ConvertFrom-Lua now rejects bare reserved words used as table keys or assignment variable names — matching the Lua 5.4 §3.1 grammar rules. Previously, invalid Lua like { end = 1 } or while = 42 was silently parsed.

# Default — throws a terminating error
ConvertFrom-Lua -InputObject '{ end = 1 }'
# Error: Reserved word 'end' cannot be used as a bare identifier key in a Lua table.
#        Use bracket notation: [\"end\"] = value.

Bracket-notation keys with reserved word strings remain fully supported:

ConvertFrom-Lua -InputObject '{ [\"end\"] = 1, [\"while\"] = 2 }' -AsHashtable
# Returns: @{ end = 1; while = 2 }

New: -SkipValidation switch for lenient import

When importing data that may not be spec-compliant, use -SkipValidation to suppress errors. Each reserved word occurrence produces its own warning, and parsing continues normally.

ConvertFrom-Lua -InputObject '{ end = 1, while = 2 }' -AsHashtable -SkipValidation
# WARNING: Reserved word 'end' used as a bare identifier key at position 2.
# WARNING: Reserved word 'while' used as a bare identifier key at position 11.
# Returns: @{ end = 1; while = 2 }

Fixed: Enum string escaping no longer double-escapes backslashes

ConvertTo-Lua -EnumsAsStrings previously produced \\\\ instead of \\ for backslashes in enum string representations due to an incorrect -replace pattern.

Technical Details

  • ConvertFrom-Lua.ps1: Added -SkipValidation switch parameter, threaded to ConvertFrom-LuaTable via -SkipValidation:$SkipValidation.
  • ConvertFrom-LuaTable.ps1: Added -SkipValidation parameter. Stored as $script:luaSkipValidation for use by recursive parser functions. Added $reservedWords array and validation after variable name extraction in the assignment parsing path — throws or warns based on skip flag.
  • Read-LuaTable.ps1: Added $reservedWords array and validation after bare identifier + = detection — throws or warns based on $script:luaSkipValidation.
  • ConvertTo-LuaTable.ps1: Fixed enum escaping: -replace '\\', '\\\\'-replace '\\', '\\'.
  • return keyword note: return is consumed as a leading keyword before assignment detection (for return { ... } patterns), so return = 42 triggers a different parse error rather than the reserved word check. Tests use while as the second assignment variable test word.
  • Tests: 8 new tests — 5 for default throw behavior (bare table keys ×2, bracket notation positive, assignment variables ×2), 3 for -SkipValidation (bare key warning, assignment warning, multiple warnings with count assertion)."