Skip to content

Commit

Permalink
Key invalid character check
Browse files Browse the repository at this point in the history
  • Loading branch information
fire015 committed Sep 30, 2014
1 parent c47ccf6 commit 232e929
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
18 changes: 11 additions & 7 deletions src/Flintstone/FlintstoneDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,19 @@ private function preserveLines($data, $reverse) {
* @return boolean
*/
private function isValidKey($key) {
if (!is_string($key)) {
throw new FlintstoneException('Key must be string');
}
if (!is_string($key)) {
throw new FlintstoneException('Key must be a string');
}

if (strlen($key) > 1024) {
throw new FlintstoneException('Maximum key length is 1024 characters');
}
if (strlen($key) > 1024) {
throw new FlintstoneException('Maximum key length is 1024 characters');
}

return true;
if (strpos($key, '=') !== false) {
throw new FlintstoneException('Key may not contain the equals character');
}

return true;
}

/**
Expand Down
20 changes: 14 additions & 6 deletions tests/FeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,27 @@ public function testInvalidKey() {
$this->db->get(1);
}

/**
* Test invalid character key
* @expectedException Flintstone\FlintstoneException
*/
public function testInvalidChrKey() {
$this->db->get('a=b');
}

/**
* Test blank key
*/
public function testBlankKey() {
$this->assertFalse($this->db->get(''));
}

/**
* Test complex key
*/
public function testComplexKey() {
$this->assertFalse($this->db->get('users:1:name'));
}
/**
* Test complex key
*/
public function testComplexKey() {
$this->assertFalse($this->db->get('users:1:name'));
}

/**
* Test huge key
Expand Down

0 comments on commit 232e929

Please sign in to comment.