Fix global loadstring lookup under strict mode #50#52
Closed
harningt wants to merge 1 commit into
Closed
Conversation
- Replaced loadstring lookup with rawget(_G or {}, 'loadstring') or load in output.lua, output_utility.lua, and hook_require.lua to prevent undeclared global accesses.
- Added strict mode validation to the test suite under the TEST_STRICT environment variable.
- Configured GitHub Actions test suite matrix to run with TEST_STRICT=1.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #52 +/- ##
===========================================
+ Coverage 95.69% 95.90% +0.21%
===========================================
Files 18 18
Lines 1021 1026 +5
===========================================
+ Hits 977 984 +7
+ Misses 44 42 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request resolves Issue #50 where importing/using the
jsonmodule under strict mode (e.g. fromstrict.lua) fails.The failure happens under Lua 5.2+ because
loadstring or loadperforms a global lookup for theloadstringvariable. Sinceloadstringis not declared or defined in these versions, accessing it directly triggers the global table's__indexmetamethod, causing a strict mode violation error:Proposed Changes
loadstringCheck: Replacedloadstring or loadwithrawget(_G or {}, "loadstring") or loadin:lua/json/encode/output.lualua/json/encode/output_utility.luatests/hook_require.luatests/hook_require.luawhen theTEST_STRICTenvironment variable is active. The check is configured to only throw for undeclared global accesses originating from the library files (lua/json/*), bypassing third-party loader environments (likeluarocksloader which referencesunpack)..github/workflows/test.yml) to run the entire test suite (across all Lua versions and interpreters) withTEST_STRICT=1enabled.Closes #50