From 0ddd12e31ccf61b4238f77e167850cb9b14ae9c2 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 5 Jan 2024 22:58:52 +0800 Subject: check invalid scope name #4547 --- xmake/core/base/interpreter.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index dfefe3438..e1cd08a78 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -956,7 +956,20 @@ end function interpreter:api_register_scope(...) -- define implementation - local implementation = function (self, scopes, scope_kind, scope_name, scope_info) + local implementation = function (self, scopes, scope_kind, ...) + local scope_args = table.pack(...) + local scope_name = scope_args[1] + local scope_info = scope_args[2] + + -- check invalid scope name, @see https://github.com/xmake-io/xmake/issues/4547 + if scope_args.n > 0 and type(scope_name) ~= "string" then + local errors = string.format("%s(%s): invalid %s name", scope_kind, scope_name, scope_kind) + local sourceinfo = debug.getinfo(2, "Sl") + if sourceinfo then + errors = string.format("%s:%s: %s", sourceinfo.short_src or sourceinfo.source, sourceinfo.currentline, errors) + end + interpreter._raise(errors) + end -- init scope for kind local scope_for_kind = scopes[scope_kind] or {} -- cgit v1.3.1