Skip to content
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

Fix load_string() ignoring the passed chunk name #6794

Merged
merged 3 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions data/test/scenarios/test_lua_name.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

# Test that an error message in Lua includes the value of the tag's name key
{GENERIC_UNIT_TEST test_lua_name (
[event]
name=start
[lua]
name=test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely not needed, but I'd prefer the name here be something more unique than just "test".

code=<<
-- Can't use assert_throws_with here because we want to test the preamble that's automatically prefixed to the error.
local ret, err = pcall(function()
local some_variable = bar
end)
unit_test.assert_contains(err, 'test', 'error contains name')
unit_test.succeed()
>>
[/lua]
[/event]
)}
2 changes: 1 addition & 1 deletion src/scripting/lua_kernel_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ bool lua_kernel_base::protected_call(lua_State * L, int nArgs, int nRets, error_
bool lua_kernel_base::load_string(char const * prog, const std::string& name, error_handler e_h)
{
// pass 't' to prevent loading bytecode which is unsafe and can be used to escape the sandbox.
int errcode = luaL_loadbufferx(mState, prog, strlen(prog), name.empty() ? name.c_str() : prog, "t");
int errcode = luaL_loadbufferx(mState, prog, strlen(prog), name.empty() ? prog : name.c_str(), "t");
if (errcode != LUA_OK) {
char const * msg = lua_tostring(mState, -1);
std::string message = msg ? msg : "null string";
Expand Down
1 change: 1 addition & 0 deletions wml_test_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
0 test_ability_id_active
0 test_ability_id_not_active
0 event_test_filter_attack
0 test_lua_name
0 filter_vision
0 test_shroud_init
0 test_shroud_place_wml
Expand Down