Skip to content

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

Draft
Marius Storhaug (MariusStorhaug) wants to merge 3 commits intomainfrom
reserved
Draft

🩹 [Patch]: Reserved words in Lua input now detected with option to skip validation#6
Marius Storhaug (MariusStorhaug) wants to merge 3 commits intomainfrom
reserved

Conversation

@MariusStorhaug
Copy link
Copy Markdown
Member

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.

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)."

@github-actions
Copy link
Copy Markdown

Super-linter summary

Language Validation result
CHECKOV Pass ✅
GITHUB_ACTIONS Pass ✅
GITLEAKS Pass ✅
GIT_MERGE_CONFLICT_MARKERS Pass ✅
JSON Pass ✅
LUA Pass ✅
MARKDOWN Pass ✅
NATURAL_LANGUAGE Pass ✅
POWERSHELL Fail ❌
PRE_COMMIT Pass ✅
SPELL_CODESPELL Pass ✅
TRIVY Pass ✅
YAML Pass ✅

Super-linter detected linting errors

For more information, see the GitHub Actions workflow run

Powered by Super-linter

POWERSHELL

�[32;1mRuleName                           �[0m�[32;1m Severity    �[0m�[32;1m ScriptName�[0m�[32;1m Line �[0m�[32;1m Message�[0m
�[32;1m--------                           �[0m �[32;1m--------    �[0m �[32;1m----------�[0m �[32;1m---- �[0m �[32;1m-------�[0m
PSAvoidLongLines                    Warning      Read-LuaTa 94    Line exceeds
                                                 ble.ps1          the configure
                                                                  d maximum len
                                                                  gth of 150 ch
                                                                  aracters


�[32;1mRuleName                           �[0m�[32;1m Severity    �[0m�[32;1m ScriptName�[0m�[32;1m Line �[0m�[32;1m Message�[0m
�[32;1m--------                           �[0m �[32;1m--------    �[0m �[32;1m----------�[0m �[32;1m---- �[0m �[32;1m-------�[0m
PSAvoidLongLines                    Warning      ConvertFro 90    Line exceeds
                                                 m-Lua.ps1        the configure
                                                                  d maximum len
                                                                  gth of 150 ch
                                                                  aracters

…e error message for reserved words in Read-LuaTable
@github-actions
Copy link
Copy Markdown

Super-linter summary

Language Validation result
CHECKOV Pass ✅
GITHUB_ACTIONS Pass ✅
GITLEAKS Pass ✅
GIT_MERGE_CONFLICT_MARKERS Pass ✅
JSON Pass ✅
LUA Pass ✅
MARKDOWN Pass ✅
NATURAL_LANGUAGE Pass ✅
POWERSHELL Fail ❌
PRE_COMMIT Pass ✅
SPELL_CODESPELL Pass ✅
TRIVY Pass ✅
YAML Pass ✅

Super-linter detected linting errors

For more information, see the GitHub Actions workflow run

Powered by Super-linter

POWERSHELL

�[32;1mRuleName                           �[0m�[32;1m Severity    �[0m�[32;1m ScriptName�[0m�[32;1m Line �[0m�[32;1m Message�[0m
�[32;1m--------                           �[0m �[32;1m--------    �[0m �[32;1m----------�[0m �[32;1m---- �[0m �[32;1m-------�[0m
PSUseConsistentIndentation          Warning      Read-LuaTa 95    Indentation n
                                                 ble.ps1          ot consistent


�[32;1mRuleName                           �[0m�[32;1m Severity    �[0m�[32;1m ScriptName�[0m�[32;1m Line �[0m�[32;1m Message�[0m
�[32;1m--------                           �[0m �[32;1m--------    �[0m �[32;1m----------�[0m �[32;1m---- �[0m �[32;1m-------�[0m
PSAlignAssignmentStatement          Warning      ConvertFro 91    Assignment st
                                                 m-Lua.ps1        atements are
                                                                  not aligned
PSAlignAssignmentStatement          Warning      ConvertFro 93    Assignment st
                                                 m-Lua.ps1        atements are
                                                                  not aligned
PSAlignAssignmentStatement          Warning      ConvertFro 94    Assignment st
                                                 m-Lua.ps1        atements are
                                                                  not aligned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate reserved words in ConvertFrom-Lua with -SkipValidation for lenient import

1 participant