dengliming commented on code in PR #667:
URL: https://github.com/apache/shenyu-dashboard/pull/667#discussion_r4110258021


##########
src/routes/Plugin/Common/CommonRuleHandle.js:
##########
@@ -33,6 +33,28 @@ const formItemLayout = {
   },
 };
 
+export const isValidHandleJSON = (handleType, value) => {
+  if (handleType !== "2" || typeof value !== "string") {

Review Comment:
   [P2] Reject an untouched JSON field instead of accepting undefined
   
   In JSON mode (`handleType === "2"`), the untouched textarea has no initial 
value, so rc-form supplies `undefined`. This early return treats it as valid. 
When creating a rule without plugin-handle fields, submitting without editing 
the textarea therefore still passes validation, and `Rule.js` assigns 
`handleJSON` directly to `handle`, leaving it undefined. This is the 
empty-submission scenario described in #639: the callback count is fixed, but 
the validation failure is not.
   
   I reproduced this with `Form.create()` wrapping the actual 
`CommonRuleHandle` component and `pluginHandleList={[]}`: `handleType` is 
`"2"`, `handleJSON` is undefined, and `form.validateFields()` reports no 
errors. An explicitly cleared string (`""`) is correctly rejected, while `"{}"` 
passes, which explains why the current string-only invalid-input tests miss the 
issue.
   
   Please separate the guards: return true for the structured-form mode, but 
return false for a non-string value in JSON mode. Add coverage for 
`validateHandleJSON("2", undefined, ...)` invoking the callback exactly once 
with an error, ideally also covering validation of an untouched textarea.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to