🎨 Block ID generation : less risk of id collision

Reported by NonSecureUniqidUsageInspection : when calling \uniqid we should provide true as second parameter.

But was causing issues as the generated string could contain a dot, and this is used in CSS and JQuery selectors (for example a "my.id" cannot be used in #my.id selector)

So we're just replacing dots with hyphens !

Was discussed with @Molkobain in 0119f6c395
This commit is contained in:
Pierre Goiffon
2020-10-27 16:58:25 +01:00
parent 8502fa7721
commit 776f32dbe1

View File

@@ -184,14 +184,16 @@ abstract class UIBlock implements iUIBlock
}
/**
* Return a unique ID for the block
* **Warning**, this shouldn't generate any dot as this will be used in CSS and JQuery selectors !
*
* @return string
* @return string a unique ID for the block
*/
protected function GenerateId()
{
/** @noinspection NonSecureUniqidUsageInspection see https://github.com/Combodo/iTop/commit/0119f6c395f314452b74c79182f4426ecff1c36d#r43596531 */
return uniqid(static::BLOCK_CODE.'-');
$sUniqId = uniqid(static::BLOCK_CODE.'-', true);
$sUniqId = str_replace('.', '-', $sUniqId);
return $sUniqId;
}
/**