Skip to content

fix(common): exclude built-in primitives from strip proto keys#16202

Merged
kamilmysliwiec merged 3 commits intonestjs:masterfrom
som14062005:fix/issue-16195
Jan 23, 2026
Merged

fix(common): exclude built-in primitives from strip proto keys#16202
kamilmysliwiec merged 3 commits intonestjs:masterfrom
som14062005:fix/issue-16195

Conversation

@som14062005
Copy link
Contributor

Description

Fixes Jest useFakeTimers() compatibility issue introduced in v11.1.10.

Issue

Closes #16195

Changes

  • Modified stripProtoKeys method to skip built-in JavaScript primitives (Date, RegExp, Error, Map, Set, WeakMap, WeakSet)
  • Maintains prototype pollution protection for regular objects
  • Added comprehensive test cases to verify Jest fake timers compatibility

Rationale

PR #16079 introduced constructor deletion for security, but Jest's fake Date objects have non-configurable constructor properties that cannot be deleted. This fix excludes built-in types while maintaining security for user-defined objects.

Testing

Skip constructor deletion for Date, RegExp, Error, Map, Set, WeakMap, and WeakSet to fix Jest useFakeTimers compatibility. Maintains prototype pollution protection for regular objects.

Fixes nestjs#16195
Skip constructor deletion for Date, RegExp, Error, Map, Set, WeakMap, and WeakSet to fix Jest useFakeTimers compatibility. Maintains prototype pollution protection for regular objects.

Fixes nestjs#16195
@coveralls
Copy link

coveralls commented Jan 15, 2026

Pull Request Test Coverage Report for Build cf3c34e0-b22e-43f4-a75c-d04670b6fced

Details

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.006%) to 89.755%

Totals Coverage Status
Change from base Build afb49988-54bb-4ac8-96c2-924e117a1e3c: 0.006%
Covered Lines: 7447
Relevant Lines: 8297

💛 - Coveralls

@som14062005
Copy link
Contributor Author

Hi @kamilmysliwiec,

When you have a moment, could you plaese review this pull request?

All tests are passing locally and CI checks are green. Please let me know if any further adjustments or additional test cases are needed.

}

// Skip built-in JavaScript primitives to avoid Jest useFakeTimers conflicts
const builtInTypes = [Date, RegExp, Error, Map, Set, WeakMap, WeakSet];
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this array outside this method? (preferebly above the class definition, or as a private static member)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok , I'll move it to a private static member for better performance.

@som14062005
Copy link
Contributor Author

@kamilmysliwiec,

Just wanted to check if there's anything I should improve in this PR to help with the review process.

@kamilmysliwiec kamilmysliwiec merged commit a1f6162 into nestjs:master Jan 23, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Version 11.1.10 brakes tests with jest useFakeTimers

3 participants