Skip to content
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

Regex segment local evaluation with int trait #72

Merged
merged 4 commits into from
May 24, 2024

Conversation

floranpagliai
Copy link
Contributor

#71

@floranpagliai floranpagliai changed the title Regex segment local evaluation with getype cast expression as int Regex segment local evaluation with int trait May 21, 2024
@@ -101,7 +101,7 @@ public function matchesTraitValue($traitValue): bool

switch ($this->operator) {
case (SegmentConditions::EQUAL):
$condition = $traitValue == $castedValue;
$condition = $traitValue === $castedValue;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As value are cast on line 91, might as well make a strict comparison

@@ -116,7 +116,7 @@ public function matchesTraitValue($traitValue): bool
$condition = $traitValue <= $castedValue;
break;
case (SegmentConditions::NOT_EQUAL):
$condition = $traitValue != $castedValue;
$condition = $traitValue !== $castedValue;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here

@@ -130,7 +130,7 @@ public function matchesTraitValue($traitValue): bool
break;
case (SegmentConditions::IN):
if (in_array($traitValueType, ['string', 'integer'])) {
$condition = in_array((string) $traitValue, explode(',', (string) $this->value));
$condition = in_array((string) $traitValue, explode(',', (string) $this->value), true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same

@@ -74,6 +74,7 @@ public function conditionParametersTraitValues()
[SegmentConditions::REGEX, 'foo', '[a-z]+', true],
[SegmentConditions::REGEX, 'FOO', '[a-z]+', false],
[SegmentConditions::REGEX, '1.2.3', '\\d', true],
[SegmentConditions::REGEX, 123, '^\\d*[13579]$', true],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a test that check that an Integer trait value can be compared against a regex

@floranpagliai floranpagliai marked this pull request as ready for review May 21, 2024 18:10
@rolodato rolodato requested a review from khvn26 May 21, 2024 18:54
Copy link
Contributor

@matthewelwell matthewelwell left a comment

Choose a reason for hiding this comment

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

Thanks @floranpagliai !

@matthewelwell matthewelwell merged commit 5e4b68f into Flagsmith:main May 24, 2024
4 checks passed
@matthewelwell
Copy link
Contributor

@floranpagliai I have just released this fix in v4.3.1 .

@floranpagliai
Copy link
Contributor Author

Thank you so much @matthewelwell for the quick review and release!

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.

3 participants