No-DB-URL-Shortener
No-DB-URL-Shortener copied to clipboard
Fix for duplicate hashes.
I believe the "_generate_new_hash" function in URLShortener.php is missing a step.
In the case where the hash already exists, it is to increment the daily count and then generate the new hash. However, the return value to the recursive call to generate the new hash is never stored. Therefore, the returned value will be the duplicate hash.
I believe the fix should be as follows:
Before:
// Check to see if the hash is already in use
if ( $this->_does_hash_exist($hash) ) {
$this->_increment_daily_count();
$this->_generate_new_hash();
}
After:
// Check to see if the hash is already in use
if ( $this->_does_hash_exist($hash) ) {
$this->_increment_daily_count();
$hash=$this->_generate_new_hash();
}