diff --git a/extension/Source/core/AbstractBuildForm.php b/extension/Source/core/AbstractBuildForm.php index 86238df6aa003d2db133a42eb1e09d744bf5dd2a..8091b14edd95207e1ff76109b138c4b2ee270334 100644 --- a/extension/Source/core/AbstractBuildForm.php +++ b/extension/Source/core/AbstractBuildForm.php @@ -697,7 +697,8 @@ abstract class AbstractBuildForm { $storeUse = str_replace(STORE_TABLE_DEFAULT, '', $storeUse); // Remove STORE_DEFAULT } // Retrieve value via FSRVD - $value = $this->store->getVar($name, $storeUse, $formElement[FE_CHECK_TYPE], $foundInStore); + $sanitizeClass=($mode == FORM_UPDATE) ? SANITIZE_ALLOW_ALL : $formElement[FE_CHECK_TYPE]; + $value = $this->store->getVar($name, $storeUse, $sanitizeClass, $foundInStore); } if ($formElement[FE_ENCODE] === FE_ENCODE_SPECIALCHAR) { diff --git a/extension/Source/core/Constants.php b/extension/Source/core/Constants.php index a98f94d49d69efb2c36e202e2240dff6932254f0..e1dce16dc015f79805dbaca259ba6109ec878c90 100644 --- a/extension/Source/core/Constants.php +++ b/extension/Source/core/Constants.php @@ -105,7 +105,7 @@ const SANITIZE_TYPE_MESSAGE_VIOLATE_CLASS = 'c'; const PATTERN_ALNUMX = '^[@\-_\.,;: \/\(\)a-zA-Z0-9ÀÈÌÒÙà èìòùÃÉÃÓÚÃáéÃóúýÂÊÎÔÛâêîôûÃÑÕãñõÄËÃÖÜŸäëïöüÿç]*$'; const PATTERN_DIGIT = '^[\d]*$'; const PATTERN_NUMERICAL = '^[\d.+-]*$'; -const PATTERN_EMAIL = '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'; +const PATTERN_EMAIL = '^([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})?$'; const PATTERN_ALLBUT = '^[^\[\]{}%\\\\#]*$'; const PATTERN_ALL = '.*'; diff --git a/extension/Tests/unit/core/BuildFormPlainTest.php b/extension/Tests/unit/core/BuildFormPlainTest.php index acb3050b5150456cc8cea23204c5516bd91ff671..f1f2cc9af74041ed16617e537b54c1df781e3e4c 100644 --- a/extension/Tests/unit/core/BuildFormPlainTest.php +++ b/extension/Tests/unit/core/BuildFormPlainTest.php @@ -152,8 +152,8 @@ class BuildFormPlainTest extends AbstractDatabaseTest { $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_EMAIL; $formElement[FE_CHECK_PATTERN] = ''; $result = $build->buildInput($formElement, 'name:1', '', $json); - $label['123'][API_ELEMENT_ATTRIBUTE]['pattern'] = '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'; - $this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$" data-pattern-error="' . SANITIZE_ALLOW_EMAIL_MESSAGE . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result); + $label['123'][API_ELEMENT_ATTRIBUTE]['pattern'] = '^([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})?$'; + $this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="^([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})?$" data-pattern-error="' . SANITIZE_ALLOW_EMAIL_MESSAGE . '" data-error="Error" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result); $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json); $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALL; diff --git a/extension/Tests/unit/core/helper/SanitizeTest.php b/extension/Tests/unit/core/helper/SanitizeTest.php index dd3d9f387905288ce432ae1212ca93e5f4a22b26..a02cac3f6046e14c2ee1d2afdefa474ce7091c72 100644 --- a/extension/Tests/unit/core/helper/SanitizeTest.php +++ b/extension/Tests/unit/core/helper/SanitizeTest.php @@ -28,7 +28,7 @@ class SanitizeTest extends TestCase { # Check '' $this->assertEquals('', Sanitize::sanitize('', SANITIZE_ALLOW_ALNUMX), "SANITIZE_ALNUMX fails"); $this->assertEquals('', Sanitize::sanitize('', SANITIZE_ALLOW_DIGIT), "SANITIZE_DIGIT fails"); - $this->assertEquals('!!email!!', Sanitize::sanitize('', SANITIZE_ALLOW_EMAIL), "SANITIZE_EMAIL fails"); + $this->assertEquals('', Sanitize::sanitize('', SANITIZE_ALLOW_EMAIL), "SANITIZE_EMAIL fails"); $this->assertEquals('', Sanitize::sanitize('', SANITIZE_ALLOW_PATTERN, '.*'), "SANITIZE_PATTERN fails"); $this->assertEquals('', Sanitize::sanitize('', SANITIZE_ALLOW_ALL), "SANITIZE_ALL fails"); $this->assertEquals('', Sanitize::sanitize('', SANITIZE_ALLOW_ALLBUT), "SANITIZE_ALLBUT fails");