]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Make lua_shape :transform() tableshape-compatible
authorVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 18 Nov 2025 12:31:15 +0000 (12:31 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 18 Nov 2025 12:31:15 +0000 (12:31 +0000)
Change :transform() return values to match tableshape behavior:
- Success: return value (not true, value)
- Failure: return nil, error (not false, error)

This is required for compatibility with lua_selectors check_args which
expects the tableshape return convention. The :check() method still
returns (bool, value_or_error) for new code.

lualib/lua_shape/core.lua

index 4ee1d32e54863de01fe719d56f62d5bf6e9756e5..667d26f206a5daa02221bae4de246f69a718ee2c 100644 (file)
@@ -81,9 +81,15 @@ local schema_methods = {
   end,
 
   -- Transform value according to schema
+  -- Returns: (value) on success, (nil, error) on failure (tableshape-compatible)
   transform = function(self, value, ctx)
     ctx = ctx or make_context("transform")
-    return self._check(self, value, ctx)
+    local ok, result = self._check(self, value, ctx)
+    if ok then
+      return result
+    else
+      return nil, result
+    end
   end,
 
   -- Make schema optional