Skip to content

fix(Utils): add guard against null rule value in validateRule#7779

Open
afsuyadi wants to merge 1 commit into
Flagsmith:mainfrom
afsuyadi:fix-error-create-segment
Open

fix(Utils): add guard against null rule value in validateRule#7779
afsuyadi wants to merge 1 commit into
Flagsmith:mainfrom
afsuyadi:fix-error-create-segment

Conversation

@afsuyadi

Copy link
Copy Markdown
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • [✔] I have read the Contributing Guide.
  • [✔] I have added information to docs/ if required so people know about the feature.
  • [✔] I have filled in the "Changes" section below.
  • [✔] I have filled in the "How did you test this code" section below.

Changes

Contributes to #7536

  1. Error happens when CreateSegment component is trying to call method validateRule() by passing an object.
  2. The method crashes when split() method is executed on a variable that isn't string-type.
  3. Inside method validateRule(), only value prop that is accessed and doesn't have its own guard, so the method crashes when it's empty (either null or undefined).
  4. I add loose equality guard, to catch only null and undefined value.

How did you test this code?

  1. I try to simulate this on my local by manually creating the Segment via UI, but it seems no error happens, because the button Create Segment itself is already been greyed out.
  2. I deduce that this error happens via API backend hit.
Screencast.from.14-06-26.11.46.58.webm

@afsuyadi afsuyadi requested a review from a team as a code owner June 14, 2026 05:09
@afsuyadi afsuyadi requested review from kyle-ssg and removed request for a team June 14, 2026 05:09
@vercel

vercel Bot commented Jun 14, 2026

Copy link
Copy Markdown

@afsuyadi is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the front-end Issue related to the React Front End Dashboard label Jun 14, 2026
@afsuyadi afsuyadi force-pushed the fix-error-create-segment branch from 3438e22 to 3662bc2 Compare June 18, 2026 02:23
@manos-saratsis

This comment was marked as spam.

@Zaimwa9 Zaimwa9 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the contribution.
It would be preferable to avoid loosy comparisons if you don't mind.
We have been ramping up on using unit tests on the frontend. validateRule would be a perfect candidate if we could add a couple of parametrized tests around it, including ones validating the fix.
👍

}
}
case 'MODULO': {
if (rule.value == null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually, let's avoid the loose comparison and keep the !rule.value. From the above (Regex), it hasn't generated an error so there is no reason for now to make a change there

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay I'll revert the change. Thanks for the review

@Zaimwa9 Zaimwa9 assigned Zaimwa9 and unassigned kyle-ssg Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

front-end Issue related to the React Front End Dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants