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 detection of primitive types on union type #1575

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fabianerni
Copy link

detect int before boolean and exclude int(1) from boolean detection
fixes #1573

Q A
Bug fix? yes
New feature? no
Doc updated no
BC breaks? no (except someone relied on the invalid conversion from 1 to true)
Deprecations? no
Tests pass? yes
Fixed tickets #1573
License MIT

detect int before boolean and exclude int(1) from boolean detection
fixes schmittjoh#1573
@@ -131,7 +131,7 @@ private function testPrimitive(mixed $data, string $type, string $format): bool

case 'bool':
case 'boolean':
return (string) (bool) $data === (string) $data;
return (string) (bool) $data === (string) $data && 1 !== $data; // prevent false positive for 1/true
Copy link
Collaborator

@goetas goetas Dec 2, 2024

Choose a reason for hiding this comment

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

would it make sense to just use is_bool? would it break any test?

@@ -475,6 +479,9 @@ public function testSerializingUnionProperties()
$serialized = $this->serialize(new UnionTypedProperties(10000));
self::assertEquals(static::getContent('data_integer'), $serialized);

$serialized = $this->serialize(new UnionTypedProperties(1));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm curious what will happen with this case:

$object = new UnionTypedProperties(0);
$object = new UnionTypedProperties('');

Can we add it as well? :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to see more cases for the getSimpleUnionProperties test: note that I did extend that test with my PR.

@bobvandevijver
Copy link
Contributor

I have opened #1582 as well, which also touches the primitive types.

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.

Serialization of union type will return bool(true) instead of int(1)
4 participants