Skip to content

Commit a01a1bf

Browse files
committed
Catch exception for invalid EntityId in GUID parser
As in PHPdoc the ClaimGuidParser::parse method should return ClaimGuidParsingExceptions This catchs previously uncaught EntityIdParsingExceptions
1 parent b6d9118 commit a01a1bf

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/Claim/ClaimGuidParser.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Wikibase\DataModel\Entity\DispatchingEntityIdParser;
66
use Wikibase\DataModel\Entity\EntityIdParser;
7+
use Wikibase\DataModel\Entity\EntityIdParsingException;
78

89
/**
910
* @since 0.5
@@ -41,7 +42,12 @@ public function parse( $serialization ) {
4142
throw new ClaimGuidParsingException( '$serialization does not have the correct number of parts' );
4243
}
4344

44-
return new ClaimGuid( $this->entityIdParser->parse( $keyParts[0] ), $keyParts[1] );
45+
try {
46+
return new ClaimGuid( $this->entityIdParser->parse( $keyParts[0] ), $keyParts[1] );
47+
}
48+
catch( EntityIdParsingException $exception ) {
49+
throw new ClaimGuidParsingException( '$serialization contains invalid EntityId: ' . $exception->getMessage() );
50+
}
4551
}
4652

47-
}
53+
}

tests/unit/Claim/ClaimGuidParserTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function invalidIdSerializationProvider() {
5656
array( '' ),
5757
array( 'q0' ),
5858
array( '1p' ),
59+
array( 'Q0$5627445f-43cb-ed6d-3adb-760e85bd17ee' ),
5960
);
6061
}
6162

0 commit comments

Comments
 (0)