-
Notifications
You must be signed in to change notification settings - Fork 29
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
Conversation
There was a problem hiding this 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.
/**
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. |
There was a problem hiding this 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. |
There was a problem hiding this 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
- Add a private
checkedFields
property
export class Schema<DataType = any, ErrorMsgType = string> {
private checkedFields: Set<string> = new Set();
// other properties and methods
}
- Update
checkForField
andcheckForFieldAsync
to use thecheckedFields
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);
}
});
test/MixedTypeSpec.js
Outdated
@@ -714,6 +714,21 @@ describe('#MixedType', () => { | |||
} | |||
}); | |||
}); | |||
|
|||
it('should handle circular proxy dependencies', () => { |
There was a problem hiding this comment.
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
f3ed75d
to
4697efe
Compare
reproduction:
https://codesandbox.io/p/sandbox/priceless-morse-whsh76
When typing something to input(name/email), an error will occur.