Skip to content

Commit ca240ba

Browse files
Ladsgroupjakobw
authored andcommitted
Prevent redirecting an entity to itself
Bug: T214920
1 parent 53967c7 commit ca240ba

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/Entity/EntityRedirect.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public function __construct( EntityId $entityId, EntityId $targetId ) {
3737
);
3838
}
3939

40+
if ( $entityId->getSerialization() === $targetId->getSerialization() ) {
41+
throw new InvalidArgumentException( '$entityId and $targetId can not be the same.' );
42+
}
43+
4044
$this->entityId = $entityId;
4145
$this->targetId = $targetId;
4246
}

tests/unit/Entity/EntityRedirectTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ public function testConstruction_baseType() {
3737
new EntityRedirect( $entityId, $targetId );
3838
}
3939

40+
public function testConstruction_sameEntity() {
41+
$this->expectException( InvalidArgumentException::class );
42+
43+
$entityId = new ItemId( 'Q123' );
44+
$targetId = new ItemId( 'Q123' );
45+
46+
new EntityRedirect( $entityId, $targetId );
47+
}
48+
4049
public function equalsProvider() {
4150
$q123 = new ItemId( 'Q123' );
4251
$q345 = new ItemId( 'Q345' );

0 commit comments

Comments
 (0)