Skip to content

fix: prevent infinite loops in circular proxy validation #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2025

Conversation

myNameIsDu
Copy link
Member

@myNameIsDu myNameIsDu commented Mar 28, 2025

reproduction:
https://codesandbox.io/p/sandbox/priceless-morse-whsh76

When typing something to input(name/email), an error will occur.

image

@myNameIsDu myNameIsDu requested a review from Copilot March 28, 2025 07:47
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses an infinite loop issue in circular proxy dependencies by incorporating a mechanism to track already validated fields.

  • Added a test case in MixedTypeSpec.js to simulate circular proxy dependencies.
  • Modified Schema.ts to include and propagate a _checkedFields array to prevent re-validating fields.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
test/MixedTypeSpec.js Adds a test to cover and ensure proper handling of circular proxies.
src/Schema.ts Introduces a _checkedFields property and propagates it through checkForField calls to avoid infinite loops.
Comments suppressed due to low confidence (1)

src/Schema.ts:11

  • [nitpick] The property name '_checkedFields' is not fully descriptive of its purpose. Consider renaming it to 'fieldsCheckedForCircularValidation' for improved clarity.
/**

Copy link

codesandbox-ci bot commented Mar 28, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@myNameIsDu myNameIsDu requested a review from Copilot March 28, 2025 07:59
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes infinite loops encountered during circular proxy validations by tracking already validated fields, and it includes a new test to verify the fix.

  • Added a test case for circular proxy dependencies in the schema.
  • Modified the Schema class to track checked fields using a new _checkedFields option to prevent infinite recursion.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
test/MixedTypeSpec.js Introduced a new test to simulate and verify circular proxy handling.
src/Schema.ts Updated the recursive check to include a _checkedFields mechanism for cycle prevention.

Copy link
Member

@simonguo simonguo left a comment

Choose a reason for hiding this comment

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

The current implementation of the _checkedFields parameter in the Schema class is used to track which fields have already been checked to avoid redundant checks. This parameter is passed around in the options object, which is not ideal since checkForField and checkForFieldAsync methods are designed for external calls.

Proposed Change

  1. Add a private checkedFields property
export class Schema<DataType = any, ErrorMsgType = string> {
  private checkedFields: Set<string> = new Set();
  // other properties and methods
}
  1. Update checkForField and checkForFieldAsync to use the checkedFields property:
    fieldChecker.otherFields?.forEach((field: string) => {
      if (!this.checkedFields.has(field)) {
        this.checkedFields.add(field);
        if (checkIfValueExists) {
          if (!isEmpty(getFieldValue(data, field, nestedObject))) {
            this.checkForField(field as T, data, options);
          }
          return;
        }
        this.checkForField(field as T, data, options);
      }
    });

@@ -714,6 +714,21 @@ describe('#MixedType', () => {
}
});
});

it('should handle circular proxy dependencies', () => {
Copy link
Member

Choose a reason for hiding this comment

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

To maintain consistency, "should" should be capitalized at the beginning

@myNameIsDu myNameIsDu force-pushed the fix/proxy branch 2 times, most recently from f3ed75d to 4697efe Compare April 3, 2025 07:57
@simonguo simonguo merged commit 4d147b9 into rsuite:master Apr 11, 2025
5 of 6 checks passed
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