Skip to content

fix(default): deepcopy table defaults on each check() call#4

Merged
unera merged 1 commit intomasterfrom
default_objects
Mar 26, 2026
Merged

fix(default): deepcopy table defaults on each check() call#4
unera merged 1 commit intomasterfrom
default_objects

Conversation

@unera
Copy link
Copy Markdown
Collaborator

@unera unera commented Mar 26, 2026

Default table values were stored as a single Lua registry reference and reused by reference on every check() call. Mutating the returned value would corrupt subsequent calls.

Fix both application sites:

  • top-level default in cv_schema_check
  • field-level default in cv_check_map

Field-level default now also runs cv_check_node on the copied value, so nested defaults are applied recursively.

Add regression test in test/inplace_default_deepcopy_test.lua.

Default table values were stored as a single Lua registry
reference and reused by reference on every check() call.
Mutating the returned value would corrupt subsequent calls.

Fix both application sites:
- top-level default in cv_schema_check
- field-level default in cv_check_map

Field-level default now also runs cv_check_node on the
copied value, so nested defaults are applied recursively.

Add regression test in test/inplace_default_deepcopy_test.lua.
@unera unera merged commit 0541ea9 into master Mar 26, 2026
1 check passed
@unera unera deleted the default_objects branch March 26, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants