diff --git a/src/classes/ExtendedGraph.class.php b/src/classes/ExtendedGraph.class.php index 46a967da..e16aaa0b 100644 --- a/src/classes/ExtendedGraph.class.php +++ b/src/classes/ExtendedGraph.class.php @@ -177,6 +177,10 @@ public function add_literal_triple($s, $p, $o, $lang = null, $dt = null) { * @return bool */ private function _add_triple($s, $p, Array $o_info) { + // Make sure the subject is not an empty string + if($s === ""){ + throw new \Tripod\Exceptions\Exception("The subject cannot be an empty string"); + } // The value $o should already have been validated by this point // It's validation differs depending on whether it is a literal or resource // So just check the subject and predicate here... diff --git a/src/mongo/MongoGraph.class.php b/src/mongo/MongoGraph.class.php index ead47088..3cded4bc 100644 --- a/src/mongo/MongoGraph.class.php +++ b/src/mongo/MongoGraph.class.php @@ -143,6 +143,9 @@ private function add_tarray_to_index($tarray) if(!isset($value['r']) || !$this->isValidTripleValue($value['r'])){ return; } + if($value['r'] === ""){ + throw new \Tripod\Exceptions\Exception("The subject cannot be an empty string"); + } } } $_i[$this->_labeller->qname_to_alias($tarray["_id"][_ID_RESOURCE])] = $predObjects; diff --git a/test/unit/ExtendedGraphTest.php b/test/unit/ExtendedGraphTest.php index 41134376..a97f9e96 100644 --- a/test/unit/ExtendedGraphTest.php +++ b/test/unit/ExtendedGraphTest.php @@ -89,6 +89,13 @@ public function addInvalidSubjectToLiteralResultsInNoTriple_Provider(){ ); } + public function testAddEmptySubjectToLiteralThrowsException() + { + $this->setExpectedException('\Tripod\Exceptions\Exception'); + $graph = new ExtendedGraph(); + $graph->add_literal_triple("", 'http://some/predicate', 'http://someplace.com'); + } + /** * @dataProvider addInvalidSubjectToLiteralResultsInNoTriple_Provider */ @@ -176,6 +183,13 @@ public function addInvalidSubjectToResourceResultsInNoTriple_Provider(){ ); } + public function testAddEmptySubjectToResourceThrowsException() + { + $this->setExpectedException('\Tripod\Exceptions\Exception'); + $graph = new ExtendedGraph(); + $graph->add_resource_triple("", 'http://some/predicate', 'http://someplace.com'); + } + /** * @dataProvider addInvalidSubjectToLiteralResultsInNoTriple_Provider */ diff --git a/test/unit/mongo/MongoGraphTest.php b/test/unit/mongo/MongoGraphTest.php index 304027b7..512cac19 100644 --- a/test/unit/mongo/MongoGraphTest.php +++ b/test/unit/mongo/MongoGraphTest.php @@ -229,6 +229,22 @@ public function addTripodArrayContainingInvalidSubject_Provider(){ ); } + public function testAddTripodArrayContainingEmptySubject() + { + $this->setExpectedException('\Tripod\Exceptions\Exception'); + $doc = array( + "_id"=>array("r"=>"", "c"=>"http://talisaspire.com/works/4d101f63c10a6-2"), + "_version"=>0, + "rdf:type"=>array( + array("l"=>"a Value"), + ), + "bibo:isbn13"=>array("l"=>"9211234567890"), + ); + + $g = new \Tripod\Mongo\MongoGraph(); + $g->add_tripod_array($doc); + } + public function testAddTripodArrayContainingValidResourceValues() {