From 30ca2761e6022ed05cb786ccb2d1f886d436d2c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be> Date: Tue, 16 Oct 2018 17:32:58 +0200 Subject: [PATCH] :sparkles: feat(attributes) Set HTML5 pattern attribute for StringAttribute Also added formnovalidate="formnovalidate" to all submit inputs which should not validate data. issue #5910 --- ihtml/themes/breezy/islocked.tpl | 2 +- ihtml/themes/breezy/management/actionmenu.tpl | 2 +- ihtml/themes/breezy/management/tabfooter.tpl | 4 ++-- ihtml/themes/breezy/restore-confirm.tpl | 2 +- ihtml/themes/breezy/simple-remove.tpl | 2 +- ihtml/themes/breezy/simple-select-list.tpl | 2 +- ihtml/themes/breezy/template.tpl | 2 +- include/class_CopyPasteHandler.inc | 4 ++-- include/class_SnapshotDialogs.inc | 4 ++-- include/class_baseSelector.inc | 2 +- include/class_ldapSizeLimit.inc | 2 +- include/class_listing.inc | 2 +- .../class_ManagementConfigurationDialog.inc | 2 +- .../attributes/class_StringAttribute.inc | 12 +++++++++++- include/simpleplugin/class_dialogAttributes.inc | 2 +- include/simpleplugin/class_simpleManagement.inc | 4 ++-- include/simpleplugin/class_simplePlugin.inc | 4 ++-- include/simpleplugin/class_simpleService.inc | 2 +- plugins/admin/acl/class_aclAssignment.inc | 2 +- plugins/admin/acl/class_aclManagement.inc | 2 +- plugins/admin/acl/remove.tpl | 2 +- plugins/admin/aclrole/acleditiondialog.tpl | 4 ++-- plugins/personal/generic/class_user.inc | 4 ++-- setup/setup_migrate_accounts.tpl | 2 +- 24 files changed, 41 insertions(+), 31 deletions(-) diff --git a/ihtml/themes/breezy/islocked.tpl b/ihtml/themes/breezy/islocked.tpl index 464f78b70..1d6cbbc0e 100644 --- a/ihtml/themes/breezy/islocked.tpl +++ b/ihtml/themes/breezy/islocked.tpl @@ -24,7 +24,7 @@ <input type="submit" name="open_readonly" value="{t}Read only{/t}"/> {/if} - <input type="submit" name="cancel_lock" value="{t}Cancel{/t}"/> + <input type="submit" formnovalidate="formnovalidate" name="cancel_lock" value="{t}Cancel{/t}"/> </p> <input type="hidden" name="dn" value="{$dn}"/> diff --git a/ihtml/themes/breezy/management/actionmenu.tpl b/ihtml/themes/breezy/management/actionmenu.tpl index faa3cb5ce..8d9d3f491 100644 --- a/ihtml/themes/breezy/management/actionmenu.tpl +++ b/ihtml/themes/breezy/management/actionmenu.tpl @@ -24,7 +24,7 @@ <div id="pulldown"> <input type="hidden" name="act" id="actionmenu" value=""/> - <div style="display:none"><input type="submit" name="exec_act" id="exec_act" value=""/></div> + <div style="display:none"><input type="submit" formnovalidate="formnovalidate" name="exec_act" id="exec_act" value=""/></div> <ul class="level1" id="root"> <li> <a href="#">{t}Actions{/t} <img class="center optional" src="images/down-arrow.png" alt="down arrow"/></a> diff --git a/ihtml/themes/breezy/management/tabfooter.tpl b/ihtml/themes/breezy/management/tabfooter.tpl index 0d9f8477d..aa1e7ad46 100644 --- a/ihtml/themes/breezy/management/tabfooter.tpl +++ b/ihtml/themes/breezy/management/tabfooter.tpl @@ -1,6 +1,6 @@ {if $readOnly} <p class="plugbottom"> - <input type="submit" name="edit_cancel" value="{msgPool type=cancelButton}"/> + <input type="submit" formnovalidate="formnovalidate" name="edit_cancel" value="{msgPool type=cancelButton}"/> </p> {else} <p class="plugbottom"> @@ -10,6 +10,6 @@ <input type="submit" name="edit_apply" value="{msgPool type=applyButton}"/> {/if} - <input type="submit" name="edit_cancel" value="{msgPool type=cancelButton}"/> + <input type="submit" formnovalidate="formnovalidate" name="edit_cancel" value="{msgPool type=cancelButton}"/> </p> {/if} diff --git a/ihtml/themes/breezy/restore-confirm.tpl b/ihtml/themes/breezy/restore-confirm.tpl index 782f734a8..17df7ff41 100644 --- a/ihtml/themes/breezy/restore-confirm.tpl +++ b/ihtml/themes/breezy/restore-confirm.tpl @@ -23,7 +23,7 @@ <p class="plugbottom"> <input type="submit" name="restore_confirmed" value="{t}Continue{/t}"/> - <input type="submit" name="restore_cancel" value="{msgPool type=cancelButton}"/> + <input type="submit" formnovalidate="formnovalidate" name="restore_cancel" value="{msgPool type=cancelButton}"/> </p> </div> </div> diff --git a/ihtml/themes/breezy/simple-remove.tpl b/ihtml/themes/breezy/simple-remove.tpl index e182eeb36..2f40e8362 100644 --- a/ihtml/themes/breezy/simple-remove.tpl +++ b/ihtml/themes/breezy/simple-remove.tpl @@ -22,7 +22,7 @@ <p class="plugbottom"> <input type="submit" name="delete_confirmed" value="{msgPool type=delButton}"/> - <input type="submit" name="delete_cancel" value="{msgPool type=cancelButton}"/> + <input type="submit" formnovalidate="formnovalidate" name="delete_cancel" value="{msgPool type=cancelButton}"/> </p> </div> </div> diff --git a/ihtml/themes/breezy/simple-select-list.tpl b/ihtml/themes/breezy/simple-select-list.tpl index 0e3284fa0..8465f4c00 100644 --- a/ihtml/themes/breezy/simple-select-list.tpl +++ b/ihtml/themes/breezy/simple-select-list.tpl @@ -5,5 +5,5 @@ <input type="submit" name="add_finish" value="{msgPool type=addButton}"/> {/if} - <input type="submit" name="add_cancel" value="{msgPool type=cancelButton}"/> + <input type="submit" formnovalidate="formnovalidate" name="add_cancel" value="{msgPool type=cancelButton}"/> </p> diff --git a/ihtml/themes/breezy/template.tpl b/ihtml/themes/breezy/template.tpl index 0aa9b9cab..1dc41fa52 100644 --- a/ihtml/themes/breezy/template.tpl +++ b/ihtml/themes/breezy/template.tpl @@ -23,5 +23,5 @@ <p class="plugbottom"> <input type="submit" name="template_continue" value="{t}Continue{/t}"/> - <input type="submit" name="template_cancel" value="{msgPool type=cancelButton}"/> + <input type="submit" formnovalidate="formnovalidate" name="template_cancel" value="{msgPool type=cancelButton}"/> </p> diff --git a/include/class_CopyPasteHandler.inc b/include/class_CopyPasteHandler.inc index a3ba4c952..890c40f19 100644 --- a/include/class_CopyPasteHandler.inc +++ b/include/class_CopyPasteHandler.inc @@ -256,8 +256,8 @@ class CopyPasteHandler $display .= '<p class="plugbottom">'."\n"; $display .= '<input type="submit" name="edit_finish" style="width:80px" value="'.msgPool::okButton().'"/>'."\n"; $display .= " \n"; - $display .= '<input type="submit" name="abort_current_cut-copy_operation" value="'.msgPool::cancelButton().'"/>'."\n"; - $display .= '<input type="submit" name="abort_all_cut-copy_operations" value="'._('Cancel all').'"/>'."\n"; + $display .= '<input type="submit" formnovalidate="formnovalidate" name="abort_current_cut-copy_operation" value="'.msgPool::cancelButton().'"/>'."\n"; + $display .= '<input type="submit" formnovalidate="formnovalidate" name="abort_all_cut-copy_operations" value="'._('Cancel all').'"/>'."\n"; $display .= '</p>'; } return $display; diff --git a/include/class_SnapshotDialogs.inc b/include/class_SnapshotDialogs.inc index 52385a624..9fbbe4f75 100644 --- a/include/class_SnapshotDialogs.inc +++ b/include/class_SnapshotDialogs.inc @@ -107,7 +107,7 @@ class SnapshotCreateDialog extends simplePlugin $str .= '<p class="plugbottom">'. ' <input type="submit" name="edit_finish" value="'.msgPool::saveButton().'"/> '. - ' <input type="submit" name="edit_cancel" value="'.msgPool::cancelButton().'"/>'. + ' <input type="submit" formnovalidate="formnovalidate" name="edit_cancel" value="'.msgPool::cancelButton().'"/>'. '</p>'; return $str; @@ -342,7 +342,7 @@ class SnapshotRestoreDialog extends simplePlugin $smarty->assign('SnapshotHandlerACL', $acl); $str = parent::execute(); $str .= '<p class="plugbottom">'. - ' <input type="submit" name="edit_cancel" value="'.msgPool::backButton().'"/>'. + ' <input type="submit" formnovalidate="formnovalidate" name="edit_cancel" value="'.msgPool::backButton().'"/>'. '</p>'; } diff --git a/include/class_baseSelector.inc b/include/class_baseSelector.inc index 5050b7ca0..f4311c2d9 100644 --- a/include/class_baseSelector.inc +++ b/include/class_baseSelector.inc @@ -260,7 +260,7 @@ class baseSelector if ($this->submitButton) { $this->tree .= " <input class='center' type='image' src='geticon.php?context=actions&icon=submit&size=16' title='"._("Submit")."' name='submit_base_".$this->pid."' id='submit_base_".$this->pid."' alt='"._("Submit")."'>"; } - $this->tree .= '<input type="submit" style="display:none" name="submit_tree_base_'.$this->pid.'" id="submit_tree_base_'.$this->pid.'"/>'; + $this->tree .= '<input type="submit" formnovalidate="formnovalidate" style="display:none" name="submit_tree_base_'.$this->pid.'" id="submit_tree_base_'.$this->pid.'"/>'; $this->tree .= '<input type="hidden" name="bs_rebase_'.$this->pid.'" id="bs_rebase_'.$this->pid.'"/>'; $this->tree .= '<input type="hidden" name="BPID" id="BPID" value="'.$this->pid.'"/>'; } diff --git a/include/class_ldapSizeLimit.inc b/include/class_ldapSizeLimit.inc index 32d3666fb..69d5e35ca 100644 --- a/include/class_ldapSizeLimit.inc +++ b/include/class_ldapSizeLimit.inc @@ -128,7 +128,7 @@ class ldapSizeLimit function renderWarning() { if (($this->sizeLimit >= 10000000) || $this->limitExceeded) { - $config = '<input type="submit" name="edit_sizelimit" value="'._('Configure').'"/>'; + $config = '<input type="submit" name="edit_sizelimit" value="'._('Configure').'" formnovalidate="formnovalidate"/>'; } else { $config = ''; } diff --git a/include/class_listing.inc b/include/class_listing.inc index 5c7a6ca89..0db3db001 100644 --- a/include/class_listing.inc +++ b/include/class_listing.inc @@ -1309,7 +1309,7 @@ class listing // Load shortcut $result = '<input type="hidden" name="act" id="actionmenu" value="">'. - '<div style="display:none"><input type="submit" name="exec_act" id="exec_act" value=""/></div>'. + '<div style="display:none"><input type="submit" formnovalidate="formnovalidate" name="exec_act" id="exec_act" value=""/></div>'. '<ul class="level1" id="root"><li><a href="#">'._('Actions'). ' <img class="center optional" src="images/down-arrow.png" alt="down arrow"/></a>'; diff --git a/include/management/class_ManagementConfigurationDialog.inc b/include/management/class_ManagementConfigurationDialog.inc index 70e3664e1..cfdcc22b7 100644 --- a/include/management/class_ManagementConfigurationDialog.inc +++ b/include/management/class_ManagementConfigurationDialog.inc @@ -128,7 +128,7 @@ class ManagementConfigurationDialog extends simplePlugin $str .= '<p class="plugbottom">'. ' <input type="submit" name="edit_finish" value="'.msgPool::saveButton().'"/> '. - ' <input type="submit" name="edit_cancel" value="'.msgPool::cancelButton().'"/>'. + ' <input type="submit" formnovalidate="formnovalidate" name="edit_cancel" value="'.msgPool::cancelButton().'"/>'. '</p>'; return $str; diff --git a/include/simpleplugin/attributes/class_StringAttribute.inc b/include/simpleplugin/attributes/class_StringAttribute.inc index 575ae19ee..632ec4bea 100644 --- a/include/simpleplugin/attributes/class_StringAttribute.inc +++ b/include/simpleplugin/attributes/class_StringAttribute.inc @@ -28,6 +28,7 @@ class StringAttribute extends Attribute protected $autocomplete = NULL; protected $trim = FALSE; protected $inputType = 'text'; + protected $html5pattern = NULL; /*! \brief The constructor of StringAttribute * @@ -43,7 +44,7 @@ class StringAttribute extends Attribute function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = "", $acl = "", $regexp = "", $example = NULL) { parent::__construct($label, $description, $ldapName, $required, $defaultValue, $acl); - $this->pattern = $regexp; + $this->setPattern($regexp); $this->example = ($example === NULL ? $defaultValue : $example); } @@ -55,6 +56,12 @@ class StringAttribute extends Attribute function setPattern ($pattern) { $this->pattern = $pattern; + if (preg_match('/^(.)(.*)\1$/', $pattern, $m)) { + // First and last characters are the same means no modifiers are in use + $this->html5pattern = $m[2]; + } else { + $this->html5pattern = NULL; + } } function renderFormInput () @@ -70,6 +77,9 @@ class StringAttribute extends Attribute if ($this->autocomplete !== NULL) { $attributes['autocomplete'] = ($this->autocomplete ? 'on' : 'off' ); } + if ($this->html5pattern !== NULL) { + $attributes['pattern'] = htmlentities($this->html5pattern, ENT_COMPAT, 'UTF-8'); + } $display = $this->renderInputField($this->inputType, $id, $attributes); return $this->renderAcl($display); } diff --git a/include/simpleplugin/class_dialogAttributes.inc b/include/simpleplugin/class_dialogAttributes.inc index f9afa2314..c0169875b 100644 --- a/include/simpleplugin/class_dialogAttributes.inc +++ b/include/simpleplugin/class_dialogAttributes.inc @@ -882,7 +882,7 @@ class GenericSimplePluginDialog extends GenericDialog { return '<div style="width:100%; text-align:right; clear:both; float:none;">'. ' <input type="submit" name="'.$this->post_finish.'" value="'.msgPool::saveButton().'"/> '. - ' <input type="submit" name="'.$this->post_cancel.'" value="'.msgPool::cancelButton().'"/>'. + ' <input type="submit" formnovalidate="formnovalidate" name="'.$this->post_cancel.'" value="'.msgPool::cancelButton().'"/>'. '</div>'; } diff --git a/include/simpleplugin/class_simpleManagement.inc b/include/simpleplugin/class_simpleManagement.inc index d1d525eaa..64f495341 100644 --- a/include/simpleplugin/class_simpleManagement.inc +++ b/include/simpleplugin/class_simpleManagement.inc @@ -637,7 +637,7 @@ class simpleManagement $str = ''; if ($this->tabObject->readOnly()) { $str .= '<p class="plugbottom">'."\n". - '<input type="submit" name="edit_cancel" value="'.msgPool::cancelButton().'">'."\n". + '<input type="submit" formnovalidate="formnovalidate" name="edit_cancel" value="'.msgPool::cancelButton().'">'."\n". '</p>'; return $str; } else { @@ -649,7 +649,7 @@ class simpleManagement $str .= '<input type="submit" name="edit_apply" value="'.msgPool::applyButton().'"/>'."\n"; $str .= " \n"; } - $str .= '<input type="submit" name="edit_cancel" value="'.msgPool::cancelButton().'"/>'."\n"; + $str .= '<input type="submit" formnovalidate="formnovalidate" name="edit_cancel" value="'.msgPool::cancelButton().'"/>'."\n"; $str .= '</p>'; } return $str; diff --git a/include/simpleplugin/class_simplePlugin.inc b/include/simpleplugin/class_simplePlugin.inc index c23ee21a9..cdec82add 100644 --- a/include/simpleplugin/class_simplePlugin.inc +++ b/include/simpleplugin/class_simplePlugin.inc @@ -788,7 +788,7 @@ class simplePlugin $state = ''; } $display = '<div width="100%"><p><b>'.$text.'</b><br/>'."\n"; - $display .= '<input type="submit" value="'.$button_text.'" name="'.$name.'" '.$state.'></p></div><hr class="separator"/>'; + $display .= '<input type="submit" formnovalidate="formnovalidate" value="'.$button_text.'" name="'.$name.'" '.$state.'></p></div><hr class="separator"/>'; return $display; } @@ -2174,7 +2174,7 @@ class simplePlugin if (session::is_set('edit')) { $display .= '<input type="submit" name="edit_finish" style="width:80px" value="'.msgPool::okButton().'"/>'."\n"; $display .= ' '; - $display .= '<input type="submit" name="edit_cancel" value="'.msgPool::cancelButton().'"/>'."\n"; + $display .= '<input type="submit" formnovalidate="formnovalidate" name="edit_cancel" value="'.msgPool::cancelButton().'"/>'."\n"; } else { /* Only display edit button if there is at least one attribute editable */ if (preg_match('/r/', $ui->get_permissions($entry_dn, $plCategory.'/'.$tabObject->current))) { diff --git a/include/simpleplugin/class_simpleService.inc b/include/simpleplugin/class_simpleService.inc index d552dd10f..f7d52841d 100644 --- a/include/simpleplugin/class_simpleService.inc +++ b/include/simpleplugin/class_simpleService.inc @@ -54,7 +54,7 @@ class simpleService extends simplePlugin if (!$this->dialog) { $str .= '<p class="plugbottom servicebottom">'. ' <input type="submit" name="SaveService" value="'.msgPool::saveButton().'"/> '. - ' <input type="submit" name="CancelService" value="'.msgPool::cancelButton().'"/>'. + ' <input type="submit" formnovalidate="formnovalidate" name="CancelService" value="'.msgPool::cancelButton().'"/>'. '</div>'; } diff --git a/plugins/admin/acl/class_aclAssignment.inc b/plugins/admin/acl/class_aclAssignment.inc index 0421a222b..721eff329 100644 --- a/plugins/admin/acl/class_aclAssignment.inc +++ b/plugins/admin/acl/class_aclAssignment.inc @@ -101,7 +101,7 @@ class aclAssignmentDialogWindow extends simplePlugin '<p class="plugbottom">'. ' <input type="submit" name="add_acl_finish" value="{msgPool type=addButton}"/>'. ' '. - ' <input type="submit" name="add_acl_cancel" value="{msgPool type=cancelButton}"/>'. + ' <input type="submit" formnovalidate="formnovalidate" name="add_acl_cancel" value="{msgPool type=cancelButton}"/>'. '</p>'); } return $display; diff --git a/plugins/admin/acl/class_aclManagement.inc b/plugins/admin/acl/class_aclManagement.inc index 540d53c1b..439a9619b 100644 --- a/plugins/admin/acl/class_aclManagement.inc +++ b/plugins/admin/acl/class_aclManagement.inc @@ -92,7 +92,7 @@ class aclAssignmentCreationDialog extends simplePlugin return parent::execute()."\n". '<p class="plugbottom">'."\n". ' <input type="submit" name="'.$this->post_finish.'" value="'.msgPool::addButton().'"/> '."\n". - ' <input type="submit" name="'.$this->post_cancel.'" value="'.msgPool::cancelButton().'"/>'."\n". + ' <input type="submit" formnovalidate="formnovalidate" name="'.$this->post_cancel.'" value="'.msgPool::cancelButton().'"/>'."\n". '</p>'; } } diff --git a/plugins/admin/acl/remove.tpl b/plugins/admin/acl/remove.tpl index ea079d264..817e0e926 100644 --- a/plugins/admin/acl/remove.tpl +++ b/plugins/admin/acl/remove.tpl @@ -22,7 +22,7 @@ <p class="plugbottom"> <input type="submit" name="delete_confirmed" value="{msgPool type=delButton}"/> - <input type="submit" name="delete_cancel" value="{msgPool type=cancelButton}"/> + <input type="submit" formnovalidate="formnovalidate" name="delete_cancel" value="{msgPool type=cancelButton}"/> </p> </div> </div> diff --git a/plugins/admin/aclrole/acleditiondialog.tpl b/plugins/admin/aclrole/acleditiondialog.tpl index b92d8a122..36174c6ee 100644 --- a/plugins/admin/aclrole/acleditiondialog.tpl +++ b/plugins/admin/aclrole/acleditiondialog.tpl @@ -4,13 +4,13 @@ {if $dialogState eq 'create'} <p class="plugbottom"> <input type="submit" name="add_finish" value="{msgPool type=applyButton}"/> - <input type="submit" name="add_cancel" value="{msgPool type=cancelButton}"/> + <input type="submit" formnovalidate="formnovalidate" name="add_cancel" value="{msgPool type=cancelButton}"/> </p> {/if} {if $dialogState eq 'edit'} <p class="plugbottom"> <input type="submit" name="submit_edit_acl" value="{msgPool type=applyButton}"/> - <input type="submit" name="cancel_edit_acl" value="{msgPool type=cancelButton}"/> + <input type="submit" formnovalidate="formnovalidate" name="cancel_edit_acl" value="{msgPool type=cancelButton}"/> </> {/if} diff --git a/plugins/personal/generic/class_user.inc b/plugins/personal/generic/class_user.inc index 972c070bc..1a44faa4f 100644 --- a/plugins/personal/generic/class_user.inc +++ b/plugins/personal/generic/class_user.inc @@ -93,12 +93,12 @@ class user extends simplePlugin new StringAttribute ( _('Last name'), _('Last name of this user'), 'sn', TRUE, - '', '', '/[^,+"?()=<>;\\\\]/' + '', '', '/^[^,+"?()=<>;\\\\]+$/' ), new StringAttribute ( _('First name'), _('First name of this user'), 'givenName', TRUE, - '', '', '/[^,+"?()=<>;\\\\]/' + '', '', '/^[^,+"?()=<>;\\\\]+$/' ), new TextAreaAttribute ( _('Description'), _('Short description of the user'), diff --git a/setup/setup_migrate_accounts.tpl b/setup/setup_migrate_accounts.tpl index a2ebcdd47..0d2bcbeba 100644 --- a/setup/setup_migrate_accounts.tpl +++ b/setup/setup_migrate_accounts.tpl @@ -65,7 +65,7 @@ dn: {$entry.dn} <div style="width:99%; text-align:right; padding-top:5px;"> <input type="submit" name="dialog_confirm" value="{t}Apply{/t}"/> - <input type="submit" name="dialog_cancel" value="{t}Cancel{/t}"/> + <input type="submit" formnovalidate="formnovalidate" name="dialog_cancel" value="{t}Cancel{/t}"/> </div> </div> </div> -- GitLab