Skip to content

fix: prevent infinite recursion with self-referential getters (#15822)#15831

Merged
cpojer merged 4 commits intojestjs:mainfrom
larshvile:fix-infinite-recursion-getters
Oct 3, 2025
Merged

fix: prevent infinite recursion with self-referential getters (#15822)#15831
cpojer merged 4 commits intojestjs:mainfrom
larshvile:fix-infinite-recursion-getters

Conversation

@larshvile
Copy link
Copy Markdown
Contributor

Fixes #15822

Summary

  • Modified deepCyclicCopyReplaceable to detect self-referential getters that return instances of the same class
  • Replace such getters with [Getter] placeholder to prevent infinite recursion
  • Added tests covering various getter scenarios

The fix only affects getters that would cause infinite recursion while preserving all other getter functionality.

Test plan

  • Unit tests in deepCyclicCopyReplaceable.test.ts
  • Integration tests in printDiffOrStringify.test.ts and matchers.test.js
  • All existing tests continue to pass

larshvile and others added 2 commits September 13, 2025 15:29
Fixes jestjs#15822 by detecting when getters return instances of the same class
and replacing them with '[Getter]' placeholder to avoid stack overflow.

The fix works by checking if the getter result's constructor matches the
containing object's constructor (excluding plain Objects) and short-circuits
the recursion in those cases.

Co-Authored-By: Claude <noreply@anthropic.com>
@netlify
Copy link
Copy Markdown

netlify Bot commented Sep 21, 2025

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit f34ad06
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/68d8e3965dd0f60008a08b53
😎 Deploy Preview https://deploy-preview-15831--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Sep 21, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Sep 21, 2025

Open in StackBlitz

babel-jest

npm i https://pkg.pr.new/babel-jest@15831

babel-plugin-jest-hoist

npm i https://pkg.pr.new/babel-plugin-jest-hoist@15831

babel-preset-jest

npm i https://pkg.pr.new/babel-preset-jest@15831

create-jest

npm i https://pkg.pr.new/create-jest@15831

@jest/diff-sequences

npm i https://pkg.pr.new/@jest/diff-sequences@15831

expect

npm i https://pkg.pr.new/expect@15831

@jest/expect-utils

npm i https://pkg.pr.new/@jest/expect-utils@15831

jest

npm i https://pkg.pr.new/jest@15831

jest-changed-files

npm i https://pkg.pr.new/jest-changed-files@15831

jest-circus

npm i https://pkg.pr.new/jest-circus@15831

jest-cli

npm i https://pkg.pr.new/jest-cli@15831

jest-config

npm i https://pkg.pr.new/jest-config@15831

@jest/console

npm i https://pkg.pr.new/@jest/console@15831

@jest/core

npm i https://pkg.pr.new/@jest/core@15831

@jest/create-cache-key-function

npm i https://pkg.pr.new/@jest/create-cache-key-function@15831

jest-diff

npm i https://pkg.pr.new/jest-diff@15831

jest-docblock

npm i https://pkg.pr.new/jest-docblock@15831

jest-each

npm i https://pkg.pr.new/jest-each@15831

@jest/environment

npm i https://pkg.pr.new/@jest/environment@15831

jest-environment-jsdom

npm i https://pkg.pr.new/jest-environment-jsdom@15831

@jest/environment-jsdom-abstract

npm i https://pkg.pr.new/@jest/environment-jsdom-abstract@15831

jest-environment-node

npm i https://pkg.pr.new/jest-environment-node@15831

@jest/expect

npm i https://pkg.pr.new/@jest/expect@15831

@jest/fake-timers

npm i https://pkg.pr.new/@jest/fake-timers@15831

@jest/get-type

npm i https://pkg.pr.new/@jest/get-type@15831

@jest/globals

npm i https://pkg.pr.new/@jest/globals@15831

jest-haste-map

npm i https://pkg.pr.new/jest-haste-map@15831

jest-jasmine2

npm i https://pkg.pr.new/jest-jasmine2@15831

jest-leak-detector

npm i https://pkg.pr.new/jest-leak-detector@15831

jest-matcher-utils

npm i https://pkg.pr.new/jest-matcher-utils@15831

jest-message-util

npm i https://pkg.pr.new/jest-message-util@15831

jest-mock

npm i https://pkg.pr.new/jest-mock@15831

@jest/pattern

npm i https://pkg.pr.new/@jest/pattern@15831

jest-phabricator

npm i https://pkg.pr.new/jest-phabricator@15831

jest-regex-util

npm i https://pkg.pr.new/jest-regex-util@15831

@jest/reporters

npm i https://pkg.pr.new/@jest/reporters@15831

jest-resolve

npm i https://pkg.pr.new/jest-resolve@15831

jest-resolve-dependencies

npm i https://pkg.pr.new/jest-resolve-dependencies@15831

jest-runner

npm i https://pkg.pr.new/jest-runner@15831

jest-runtime

npm i https://pkg.pr.new/jest-runtime@15831

@jest/schemas

npm i https://pkg.pr.new/@jest/schemas@15831

jest-snapshot

npm i https://pkg.pr.new/jest-snapshot@15831

@jest/snapshot-utils

npm i https://pkg.pr.new/@jest/snapshot-utils@15831

@jest/source-map

npm i https://pkg.pr.new/@jest/source-map@15831

@jest/test-result

npm i https://pkg.pr.new/@jest/test-result@15831

@jest/test-sequencer

npm i https://pkg.pr.new/@jest/test-sequencer@15831

@jest/transform

npm i https://pkg.pr.new/@jest/transform@15831

@jest/types

npm i https://pkg.pr.new/@jest/types@15831

jest-util

npm i https://pkg.pr.new/jest-util@15831

jest-validate

npm i https://pkg.pr.new/jest-validate@15831

jest-watcher

npm i https://pkg.pr.new/jest-watcher@15831

jest-worker

npm i https://pkg.pr.new/jest-worker@15831

pretty-format

npm i https://pkg.pr.new/pretty-format@15831

commit: f34ad06

Copy link
Copy Markdown
Member

@cpojer cpojer left a comment

Choose a reason for hiding this comment

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

Yeah, this makes sense. Thank you!

@cpojer cpojer merged commit 7068712 into jestjs:main Oct 3, 2025
74 checks passed
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Nov 3, 2025

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Infinite recursion in toEqual() diff generation with getter properties

2 participants