Software / code / prosody
Comparison
tests/test.lua @ 7051:ecfa474ff570
tests/test.lua: Fix fake module() function to prevent _M from being _G (test.lua's environment), which caused modules to break the sandbox when they set _M.*
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Wed, 06 Jan 2016 00:24:06 +0000 |
| parent | 6594:fa6eb6fb4a80 |
| child | 7061:eda0feeaf759 |
comparison
equal
deleted
inserted
replaced
| 7030:b5bc9f77f096 | 7051:ecfa474ff570 |
|---|---|
| 135 print("WARNING: ", "Failed to load module: "..unitname, err); | 135 print("WARNING: ", "Failed to load module: "..unitname, err); |
| 136 return; | 136 return; |
| 137 end | 137 end |
| 138 | 138 |
| 139 local oldmodule, old_M = _fakeG.module, _fakeG._M; | 139 local oldmodule, old_M = _fakeG.module, _fakeG._M; |
| 140 _fakeG.module = function () _M = _G end | 140 _fakeG.module = function () |
| 141 setmetatable(unit, nil); | |
| 142 unit._M = unit; | |
| 143 end | |
| 141 setfenv(chunk, unit); | 144 setfenv(chunk, unit); |
| 142 local success, err = pcall(chunk); | 145 local success, err = pcall(chunk); |
| 143 _fakeG.module, _fakeG._M = oldmodule, old_M; | 146 _fakeG.module, _fakeG._M = oldmodule, old_M; |
| 144 if not success then | 147 if not success then |
| 145 print("WARNING: ", "Failed to initialise module: "..unitname, err); | 148 print("WARNING: ", "Failed to initialise module: "..unitname, err); |