Skip to content

Commit d109c4c

Browse files
lucaswerkmeisterWMDE bot
authored andcommitted
EntityId: Remove Serializable interface and methods
This removes the ability to deserialize old serializations, but nothing seems to rely on that ability: we hard-deprecated unserialize() and didn’t see any log messages for it in production. Also remove all the test cases that are “kind of an injection vector”. __unserialize() still allows injecting some invalid serializations like that, but it’s not something we want to support, so I have no idea why we would want to test it, quite frankly. Bug: T345856 Change-Id: I4850feb0b58ec6367c837f3855af50d34eedd665 Depends-On: I16cf6dfaa4c6271a158c62b4bc55372a7520488e
1 parent 30f6106 commit d109c4c

9 files changed

Lines changed: 15 additions & 156 deletions

File tree

RELEASE-NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
single array argument, which was deprecated in `Version 9.6.0 (2021-03-31)`. These should now be
77
called with a variadic argument list.
88
* Added `__serialize()` and `__unserialize()` methods to the `EntityId` interface,
9-
and deprecated the `serialize()` and `unserialize()` methods.
9+
and removed the `serialize()` and `unserialize()` methods and the `Serializable` interface.
1010
* Added native type hints to the `Statement` and `StatementList` classes
1111
* Added `strict_types=1` to `Statement.php`, `StatementList.php`, and related test files
1212
* Removed support for repository names in entity IDs (e.g. `foo:Q1234`)

src/Entity/EntityId.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
namespace Wikibase\DataModel\Entity;
44

5-
use Serializable;
6-
75
/**
86
* @license GPL-2.0-or-later
97
*/
10-
interface EntityId extends Serializable {
8+
interface EntityId {
119

1210
/**
1311
* @return string
@@ -32,21 +30,6 @@ public function __toString();
3230
*/
3331
public function equals( $target );
3432

35-
/**
36-
* @see Serializable::serialize()
37-
* @return string|null
38-
* @deprecated Use {@link self::getSerialization()} instead.
39-
*/
40-
public function serialize();
41-
42-
/**
43-
* @see Serializable::unserialize()
44-
* @param string $data
45-
* @return void
46-
* @deprecated There should be no reason to use this.
47-
*/
48-
public function unserialize( $data );
49-
5033
/**
5134
* This method replaces {@link Serializable::serialize()}.
5235
* Do not call it manually.

src/Entity/ItemId.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,10 @@ public function __serialize(): array {
6363
return [ 'serialization' => $this->serialization ];
6464
}
6565

66-
/**
67-
* @see Serializable::serialize
68-
*
69-
* @since 7.0 serialization format changed in an incompatible way
70-
*
71-
* @return string
72-
*/
73-
public function serialize() {
74-
wfDeprecated( __METHOD__, '1.41' );
75-
return $this->serialization;
76-
}
77-
7866
public function __unserialize( array $data ): void {
7967
$this->serialization = $data['serialization'];
8068
}
8169

82-
/**
83-
* @see Serializable::unserialize
84-
*
85-
* @param string $serialized
86-
*/
87-
public function unserialize( $serialized ) {
88-
wfDeprecated( __METHOD__, '1.41' );
89-
$array = json_decode( $serialized );
90-
$this->serialization = is_array( $array ) ? $array[1] : $serialized;
91-
$this->serialization = $this->serialization ?? '';
92-
}
93-
9470
/**
9571
* Construct an ItemId given the numeric part of its serialization.
9672
*

src/Entity/NumericPropertyId.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,32 +59,10 @@ public function __serialize(): array {
5959
return [ 'serialization' => $this->serialization ];
6060
}
6161

62-
/**
63-
* @see Serializable::serialize
64-
*
65-
* @return string
66-
*/
67-
public function serialize() {
68-
wfDeprecated( __METHOD__, '1.41' );
69-
return $this->serialization;
70-
}
71-
7262
public function __unserialize( array $data ): void {
7363
$this->serialization = $data['serialization'];
7464
}
7565

76-
/**
77-
* @see Serializable::unserialize
78-
*
79-
* @param string $serialized
80-
*/
81-
public function unserialize( $serialized ) {
82-
wfDeprecated( __METHOD__, '1.41' );
83-
$array = json_decode( $serialized );
84-
$this->serialization = is_array( $array ) ? $array[1] : $serialized;
85-
$this->serialization = $this->serialization ?? '';
86-
}
87-
8866
/**
8967
* Construct a NumericPropertyId given the numeric part of its serialization.
9068
*

tests/fixtures/CustomEntityId.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,10 @@ public function __serialize(): array {
1616
return [ 'serialization' => $this->serialization ];
1717
}
1818

19-
/**
20-
* @see Serializable::serialize
21-
*
22-
* @return string
23-
*/
24-
public function serialize() {
25-
return $this->serialization;
26-
}
27-
2819
public function __unserialize( array $data ): void {
2920
$this->serialization = $data['serialization'];
3021
}
3122

32-
/**
33-
* @see Serializable::unserialize
34-
*
35-
* @param string $serialized
36-
*/
37-
public function unserialize( $serialized ) {
38-
$this->serialization = $serialized;
39-
}
40-
4123
/**
4224
* @return string
4325
*/

tests/unit/Entity/EntityIdTest.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@ public function testSerializationRoundtrip( EntityId $id ) {
5555

5656
public static function deserializationCompatibilityProvider(): array {
5757
return [
58-
'v05serialization' => [
59-
new ItemId( 'q123' ),
60-
'C:32:"Wikibase\DataModel\Entity\ItemId":15:{["item","Q123"]}',
61-
],
62-
'v07serialization' => [
63-
new ItemId( 'q123' ),
64-
'C:32:"Wikibase\DataModel\Entity\ItemId":4:{Q123}',
65-
],
6658
'2022-03 PHP 7.4+' => [
6759
new ItemId( 'q123' ),
6860
'O:32:"Wikibase\DataModel\Entity\ItemId":1:{s:13:"serialization";s:4:"Q123";}',
@@ -74,9 +66,6 @@ public static function deserializationCompatibilityProvider(): array {
7466
* @dataProvider deserializationCompatibilityProvider
7567
*/
7668
public function testDeserializationCompatibility( $expected, $serialization ) {
77-
if ( str_starts_with( $serialization, 'C:' ) ) {
78-
$this->expectDeprecationAndContinue( '/::unserialize/' );
79-
}
8069
$this->assertEquals(
8170
$expected,
8271
unserialize( $serialization )

tests/unit/Entity/EntityIdValueTest.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,25 +132,16 @@ public static function provideDeserializationCompatibility() {
132132
$custom = new EntityIdValue( new CustomEntityId( 'X567' ) );
133133

134134
return [
135-
'local: Version 0.5 alpha (f5b8b64)' => [
136-
'C:39:"Wikibase\DataModel\Entity\EntityIdValue":14:{["item",31337]}',
137-
$local,
138-
],
139-
'local: Version 7.0 (7fcddfc)' => [
140-
'C:39:"Wikibase\DataModel\Entity\EntityIdValue":'
141-
. '50:{C:32:"Wikibase\DataModel\Entity\ItemId":6:{Q31337}}',
142-
$local,
143-
],
144-
'custom: Version 7.0 (7fcddfc): custom' => [
145-
'C:39:"Wikibase\DataModel\Entity\EntityIdValue":'
146-
. '58:{C:42:"Wikibase\DataModel\Fixtures\CustomEntityId":4:{X567}}',
147-
$custom,
148-
],
149135
'local 2022-03 PHP 7.4+' => [
150136
'O:39:"Wikibase\DataModel\Entity\EntityIdValue":'
151137
. '1:{s:8:"entityId";O:32:"Wikibase\DataModel\Entity\ItemId":1:{s:13:"serialization";s:6:"Q31337";}}',
152138
$local,
153139
],
140+
'custom 2023-09 PHP 7.4+' => [
141+
'O:39:"Wikibase\DataModel\Entity\EntityIdValue":'
142+
. '1:{s:8:"entityId";O:42:"Wikibase\DataModel\Fixtures\CustomEntityId":1:{s:13:"serialization";s:4:"X567";}}',
143+
$custom,
144+
],
154145
];
155146
}
156147

tests/unit/Entity/ItemIdTest.php

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,33 +87,13 @@ public function testGetEntityType() {
8787

8888
public function testSerialize() {
8989
$id = new ItemId( 'Q1' );
90-
$this->expectDeprecationAndContinue( '/ItemId::serialize/' );
91-
$this->assertSame( 'Q1', $id->serialize() );
90+
$this->assertSame( [ 'serialization' => 'Q1' ], $id->__serialize() );
9291
}
9392

94-
/**
95-
* @dataProvider serializationProvider
96-
*/
97-
public function testUnserialize( $json, $expected ) {
93+
public function testUnserialize() {
9894
$id = new ItemId( 'Q1' );
99-
$this->expectDeprecationAndContinue( '/ItemId::unserialize/' );
100-
$id->unserialize( $json );
101-
$this->assertSame( $expected, $id->getSerialization() );
102-
}
103-
104-
public static function serializationProvider() {
105-
return [
106-
[ 'Q2', 'Q2' ],
107-
[ '["item","Q2"]', 'Q2' ],
108-
109-
// All these cases are kind of an injection vector and allow constructing invalid ids.
110-
[ '["string","Q2"]', 'Q2' ],
111-
[ '["","string"]', 'string' ],
112-
[ '["",""]', '' ],
113-
[ '["",2]', 2 ],
114-
[ '["",null]', '' ],
115-
[ '', '' ],
116-
];
95+
$id->__unserialize( [ 'serialization' => 'Q2' ] );
96+
$this->assertSame( 'Q2', $id->getSerialization() );
11797
}
11898

11999
/**

tests/unit/Entity/NumericPropertyIdTest.php

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,33 +86,13 @@ public function testGetEntityType() {
8686

8787
public function testSerialize() {
8888
$id = new NumericPropertyId( 'P1' );
89-
$this->expectDeprecationAndContinue( '/NumericPropertyId::serialize/' );
90-
$this->assertSame( 'P1', $id->serialize() );
89+
$this->assertSame( [ 'serialization' => 'P1' ], $id->__serialize() );
9190
}
9291

93-
/**
94-
* @dataProvider serializationProvider
95-
*/
96-
public function testUnserialize( $json, $expected ) {
92+
public function testUnserialize() {
9793
$id = new NumericPropertyId( 'P1' );
98-
$this->expectDeprecationAndContinue( '/NumericPropertyId::unserialize/' );
99-
$id->unserialize( $json );
100-
$this->assertSame( $expected, $id->getSerialization() );
101-
}
102-
103-
public static function serializationProvider() {
104-
return [
105-
[ 'P2', 'P2' ],
106-
[ '["property","P2"]', 'P2' ],
107-
108-
// All these cases are kind of an injection vector and allow constructing invalid ids.
109-
[ '["string","P2"]', 'P2' ],
110-
[ '["","string"]', 'string' ],
111-
[ '["",""]', '' ],
112-
[ '["",2]', 2 ],
113-
[ '["",null]', '' ],
114-
[ '', '' ],
115-
];
94+
$id->__unserialize( [ 'serialization' => 'P2' ] );
95+
$this->assertSame( 'P2', $id->getSerialization() );
11696
}
11797

11898
/**

0 commit comments

Comments
 (0)