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

fix: stop using is_string() for validation #233

Merged
merged 1 commit into from
Oct 18, 2024
Merged

Conversation

nand4011
Copy link
Contributor

Stop using is_string() for validation as it fails for strings that have automatically been converted into integers when used as keys in associative arrays.

Update isNullOrEmpty to check if the given value is a scalar (a string, int, float, or bool) and then check if its string value is empty instead of explicitly taking a string.

Remove a dictionary set fields test case that checks for an error when given this array: [""]. PHP will implicitly treat it as this associative array: [0 => ""], which is valid with our new validation. We need to choose whether to support integer string keys or whether to be able to reject this specific type of invalid input.

Stop using is_string() for validation as it fails for strings that have
automatically been converted into integers when used as keys in
associative arrays.

Update isNullOrEmpty to check if the given value is a scalar (a string,
int, float, or bool) and then check if its string value is empty instead
of explicitly taking a string.

Remove a dictionary set fields test case that checks for an error when
given this array: [""]. PHP will implicitly treat it as this associative
array: [0 => ""], which is valid with our new validation. We need to
choose whether to support integer string keys or whether to be able to
reject this specific type of invalid input.
@@ -2119,10 +2119,6 @@ public function testDictionarySetFieldsWithNullItems_ThrowsException()
public function testDictionarySetFieldsWithEmptyItems_IsError()
{
$dictionaryName = uniqid();
$items = [""];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately I don't know how to make this an invalid input while also allowing integer string keys.

Copy link
Contributor

@rishtigupta rishtigupta left a comment

Choose a reason for hiding this comment

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

:shipit:

@nand4011 nand4011 merged commit 711683c into main Oct 18, 2024
5 checks passed
@nand4011 nand4011 deleted the fix-string-validation branch October 18, 2024 21:43
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