Fix safeMode triggering unnecessarily

Fixes a long standing issue where when safe mode is enabled and the line endings present in the templates differed from the line endings used by the user's browser it would cause safe mode to prevent saving any changes (even when those changes did not include real changes to the code property) because the user's browser would "helpfully" change the original line endings to the line endings of the browser before sending it back to the server.
This commit is contained in:
Luke Towers 2021-01-15 14:54:31 -06:00 committed by GitHub
parent 505b1ce0db
commit 47b2aa0f15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -98,6 +98,16 @@ class CmsCompoundObject extends CmsObject
*/
public function beforeSave()
{
// Ignore line-ending only changes to the code property to avoid triggering safe mode
// when no changes actually occurred, it was just the browser reformatting line endings
if ($this->isDirty('code')) {
$oldCode = str_replace("\n", "\r\n", str_replace("\r", '', $this->getOriginal('code')));
$newCode = str_replace("\n", "\r\n", str_replace("\r", '', $this->code));
if ($oldCode === $newCode) {
$this->code = $this->getOriginal('code');
}
}
$this->checkSafeMode();
}