-
Notifications
You must be signed in to change notification settings - Fork 0
🩹 [Patch]: Reserved words in Lua input now detected with option to skip validation #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
62661b9
dca2439
10c60f9
d036c0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -58,7 +58,7 @@ | |||||
| # Enum handling | ||||||
| if ($InputObject -is [enum]) { | ||||||
| if ($EnumsAsStrings) { | ||||||
| $escaped = $InputObject.ToString() -replace '\\', '\\\\' -replace '"', '\"' | ||||||
| $escaped = $InputObject.ToString() -replace '\\', '\\' -replace '"', '\"' | ||||||
|
||||||
| $escaped = $InputObject.ToString() -replace '\\', '\\' -replace '"', '\"' | |
| $escaped = $InputObject.ToString() -replace '\\', '\\\\' -replace '"', '\"' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,14 @@ | |
| begin {} | ||
|
|
||
| process { | ||
| # Lua 5.4 reserved words per §3.1 | ||
| $reservedWords = @( | ||
| 'and', 'break', 'do', 'else', 'elseif', 'end', | ||
| 'false', 'for', 'function', 'goto', 'if', 'in', | ||
| 'local', 'nil', 'not', 'or', 'repeat', 'return', | ||
| 'then', 'true', 'until', 'while' | ||
| ) | ||
|
|
||
| $script:luaCurrentDepth++ | ||
| if ($script:luaCurrentDepth -gt $script:luaMaxDepth) { | ||
| throw "Maximum nesting depth ($($script:luaMaxDepth)) exceeded." | ||
|
|
@@ -78,6 +86,14 @@ | |
|
|
||
| if ($script:luaPos -lt $script:luaString.Length -and | ||
| $script:luaString[$script:luaPos] -eq '=') { | ||
| # Lua grammar: Name cannot be a reserved word (§3.1) | ||
| if ($ident -in $reservedWords) { | ||
| if ($script:luaSkipValidation) { | ||
| Write-Warning "Reserved word '$ident' used as a bare identifier key at position $identStart." | ||
| } else { | ||
| throw "Reserved word '$ident' cannot be used as a bare identifier key. Use bracket notation: [`"$ident`"] = value." | ||
| } | ||
|
Comment on lines
+89
to
+95
|
||
| } | ||
| # Key = value pair | ||
| $script:luaPos++ # skip = | ||
| Skip-LuaWhitespace | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reserved-word validation uses case-insensitive membership (
-in), which will flag valid identifiers likeReturn/While/Endeven though Lua keywords are case-sensitive. Use a case-sensitive check (e.g.,-cin/-ccontains, or an OrdinalHashSet) so only exact lowercase reserved words trigger errors/warnings.