Skip to content

Commit a246b2d

Browse files
author
Daniel Kinzler
committed
Merge pull request #449 from wmde/catchInvalidEntityIdInClaimGuidParser
Catch exception for invalid EntityId in GUID parser
2 parents c481062 + a01a1bf commit a246b2d

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/Claim/ClaimGuidParser.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Wikibase\DataModel\Claim;
44

55
use Wikibase\DataModel\Entity\EntityIdParser;
6+
use Wikibase\DataModel\Entity\EntityIdParsingException;
67

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

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

4652
}

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)