diff --git a/core/includes/form.inc b/core/includes/form.inc
index 3684578..e7e9775 100644
--- a/core/includes/form.inc
+++ b/core/includes/form.inc
@@ -2027,6 +2027,14 @@ function _form_builder_handle_input_element($form_id, &$element, &$form_state) {
       // be explicitly distinguished from missing input. (see below)
       $input_exists = NULL;
       $input = NestedArray::getValue($form_state['input'], $element['#parents'], $input_exists);
+      if (!empty($element['#trim'])) {
+        $input = trim($input);
+        // If the trimmed input is empty, ensure that #required and
+        // other validation handlers are triggered accordingly.
+        if ($input === '') {
+          $input_exists = FALSE;
+        }
+      }
       // For browser-submitted forms, the submitted values do not contain values
       // for certain elements (empty multiple select, unchecked checkbox).
       // During initial form processing, we add explicit NULL values for such
@@ -4317,7 +4325,7 @@ function form_pre_render_email($element) {
  * Note that #maxlength and #required is validated by _form_validate() already.
  */
 function form_validate_email(&$element, &$form_state) {
-  $value = trim($element['#value']);
+  $value = $element['#value'];
   form_set_value($element, $value, $form_state);
 
   if ($value !== '' && !valid_email_address($value)) {
@@ -4496,7 +4504,7 @@ function form_pre_render_search($element) {
  * Note that #maxlength and #required is validated by _form_validate() already.
  */
 function form_validate_url(&$element, &$form_state) {
-  $value = trim($element['#value']);
+  $value = $element['#value'];
   form_set_value($element, $value, $form_state);
 
   if ($value !== '' && !valid_url($value, TRUE)) {
@@ -4508,7 +4516,7 @@ function form_validate_url(&$element, &$form_state) {
  * Form element validation handler for #type 'color'.
  */
 function form_validate_color(&$element, &$form_state) {
-  $value = trim($element['#value']);
+  $value = $element['#value'];
 
   // Default to black if no value is given.
   // @see http://www.w3.org/TR/html5/number-state.html#color-state
diff --git a/core/modules/ban/ban.admin.inc b/core/modules/ban/ban.admin.inc
index 0ea23fc..e9e60a2 100644
--- a/core/modules/ban/ban.admin.inc
+++ b/core/modules/ban/ban.admin.inc
@@ -81,7 +81,7 @@ function ban_ip_form($form, &$form_state, $default_ip) {
  * @see ban_ip_form_submit()
  */
 function ban_ip_form_validate($form, &$form_state) {
-  $ip = trim($form_state['values']['ip']);
+  $ip = $form_state['values']['ip'];
   if (db_query("SELECT * FROM {ban_ip} WHERE ip = :ip", array(':ip' => $ip))->fetchField()) {
     form_set_error('ip', t('This IP address is already banned.'));
   }
@@ -99,7 +99,7 @@ function ban_ip_form_validate($form, &$form_state) {
  * @see ban_ip_form_validate()
  */
 function ban_ip_form_submit($form, &$form_state) {
-  $ip = trim($form_state['values']['ip']);
+  $ip = $form_state['values']['ip'];
   db_insert('ban_ip')
     ->fields(array('ip' => $ip))
     ->execute();
diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php
index fca09ba..73894ae 100644
--- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php
+++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php
@@ -285,16 +285,16 @@ public function submit(array $form, array &$form_state) {
 
     // Validate the comment's subject. If not specified, extract from comment
     // body.
-    if (trim($comment->subject->value) == '') {
+    if ($comment->subject->value === '') {
       // The body may be in any format, so:
       // 1) Filter it into HTML
       // 2) Strip out all HTML tags
       // 3) Convert entities back to plain-text.
       $comment_text = $comment->comment_body->processed;
-      $comment->subject = truncate_utf8(trim(decode_entities(strip_tags($comment_text))), 29, TRUE);
+      $comment->subject = truncate_utf8(decode_entities(strip_tags($comment_text)), 29, TRUE);
       // Edge cases where the comment body is populated only by HTML tags will
       // require a default subject.
-      if ($comment->subject->value == '') {
+      if ($comment->subject->value === '') {
         $comment->subject->value = t('(No subject)');
       }
     }
diff --git a/core/modules/contact/lib/Drupal/contact/CategoryFormController.php b/core/modules/contact/lib/Drupal/contact/CategoryFormController.php
index d60308f..0b45022 100644
--- a/core/modules/contact/lib/Drupal/contact/CategoryFormController.php
+++ b/core/modules/contact/lib/Drupal/contact/CategoryFormController.php
@@ -82,6 +82,7 @@ public function validate(array $form, array &$form_state) {
     $recipients = explode(',', $form_state['values']['recipients']);
 
     foreach ($recipients as &$recipient) {
+      // Remove any leading/trailing spaces from the exploded recipients.
       $recipient = trim($recipient);
       if (!valid_email_address($recipient)) {
         form_set_error('recipients', t('%recipient is an invalid e-mail address.', array('%recipient' => $recipient)));
diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc
index e166b82..9970bdb 100644
--- a/core/modules/file/file.field.inc
+++ b/core/modules/file/file.field.inc
@@ -154,7 +154,7 @@ function _file_generic_settings_max_filesize($element, &$form_state) {
  */
 function _file_generic_settings_extensions($element, &$form_state) {
   if (!empty($element['#value'])) {
-    $extensions = preg_replace('/([, ]+\.?)/', ' ', trim(strtolower($element['#value'])));
+    $extensions = preg_replace('/([, ]+\.?)/', ' ', strtolower($element['#value']));
     $extensions = array_filter(explode(' ', $extensions));
     $extensions = implode(' ', array_unique($extensions));
     if (!preg_match('/^([a-z0-9]+([.][a-z0-9])* ?)+$/', $extensions)) {
diff --git a/core/modules/filter/filter.admin.inc b/core/modules/filter/filter.admin.inc
index 4cc4a1f..caa5527 100644
--- a/core/modules/filter/filter.admin.inc
+++ b/core/modules/filter/filter.admin.inc
@@ -322,8 +322,8 @@ function theme_filter_admin_format_filter_order($variables) {
  * @see filter_admin_format_form_submit()
  */
 function filter_admin_format_form_validate($form, &$form_state) {
-  $format_format = trim($form_state['values']['format']);
-  $format_name = trim($form_state['values']['name']);
+  $format_format = $form_state['values']['format'];
+  $format_name = $form_state['values']['name'];
 
   // Ensure that the values to be saved later are exactly the ones validated.
   form_set_value($form['format'], $format_format, $form_state);
diff --git a/core/modules/filter/lib/Drupal/filter/FilterFormatStorageController.php b/core/modules/filter/lib/Drupal/filter/FilterFormatStorageController.php
index 1e8bdb2..d333cde 100644
--- a/core/modules/filter/lib/Drupal/filter/FilterFormatStorageController.php
+++ b/core/modules/filter/lib/Drupal/filter/FilterFormatStorageController.php
@@ -21,7 +21,6 @@ class FilterFormatStorageController extends ConfigStorageController {
   protected function preSave(EntityInterface $entity) {
     parent::preSave($entity);
 
-    $entity->name = trim($entity->label());
     $entity->cache = _filter_format_is_cacheable($entity);
     $filter_info = filter_get_filters();
     foreach ($filter_info as $name => $filter) {
diff --git a/core/modules/link/link.module b/core/modules/link/link.module
index f8ee409..54138c4 100644
--- a/core/modules/link/link.module
+++ b/core/modules/link/link.module
@@ -83,10 +83,6 @@ function link_field_is_empty($item, $field) {
  */
 function link_field_presave(EntityInterface $entity, $field, $instance, $langcode, &$items) {
   foreach ($items as $delta => &$item) {
-    // Trim any spaces around the URL and title.
-    $item['url'] = trim($item['url']);
-    $item['title'] = trim($item['title']);
-
     // Serialize the attributes array.
     $item['attributes'] = !empty($item['attributes']) ? serialize($item['attributes']) : NULL;
   }
diff --git a/core/modules/menu/menu.admin.inc b/core/modules/menu/menu.admin.inc
index de76a31..9ba763f 100644
--- a/core/modules/menu/menu.admin.inc
+++ b/core/modules/menu/menu.admin.inc
@@ -430,7 +430,7 @@ function menu_edit_item_validate($form, &$form_state) {
       $item['link_path'] = $parsed_link['path'];
     }
   }
-  if (!trim($item['link_path']) || !drupal_valid_path($item['link_path'], TRUE)) {
+  if (!$item['link_path'] || !drupal_valid_path($item['link_path'], TRUE)) {
     form_set_error('link_path', t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $item['link_path'])));
   }
 }
diff --git a/core/modules/menu/menu.module b/core/modules/menu/menu.module
index 7e26d50..a6e49a0 100644
--- a/core/modules/menu/menu.module
+++ b/core/modules/menu/menu.module
@@ -467,11 +467,10 @@ function menu_node_save(Node $node) {
         menu_link_delete($link['mlid']);
       }
     }
-    elseif (trim($link['link_title'])) {
-      $link['link_title'] = trim($link['link_title']);
+    elseif ($link['link_title']) {
       $link['link_path'] = "node/$node->nid";
-      if (trim($link['description'])) {
-        $link['options']['attributes']['title'] = trim($link['description']);
+      if ($link['description']) {
+        $link['options']['attributes']['title'] = $link['description'];
       }
       else {
         // If the description field was left empty, remove the title attribute
diff --git a/core/modules/node/content_types.inc b/core/modules/node/content_types.inc
index c958f27..a91468a 100644
--- a/core/modules/node/content_types.inc
+++ b/core/modules/node/content_types.inc
@@ -308,11 +308,11 @@ function _node_characters($length) {
  */
 function node_type_form_validate($form, &$form_state) {
   $type = new stdClass();
-  $type->type = trim($form_state['values']['type']);
-  $type->name = trim($form_state['values']['name']);
+  $type->type = $form_state['values']['type'];
+  $type->name = $form_state['values']['name'];
 
   // Work out what the type was before the user submitted this form
-  $old_type = trim($form_state['values']['old_type']);
+  $old_type = $form_state['values']['old_type'];
 
   $types = node_type_get_names();
 
@@ -341,9 +341,9 @@ function node_type_form_submit($form, &$form_state) {
 
   $type = node_type_set_defaults();
 
-  $type->type = trim($form_state['values']['type']);
-  $type->name = trim($form_state['values']['name']);
-  $type->orig_type = trim($form_state['values']['orig_type']);
+  $type->type = $form_state['values']['type'];
+  $type->name = $form_state['values']['name'];
+  $type->orig_type = $form_state['values']['orig_type'];
   $type->old_type = isset($form_state['values']['old_type']) ? $form_state['values']['old_type'] : $type->type;
 
   $type->description = $form_state['values']['description'];
diff --git a/core/modules/path/path.admin.inc b/core/modules/path/path.admin.inc
index 0535454..6aa721a 100644
--- a/core/modules/path/path.admin.inc
+++ b/core/modules/path/path.admin.inc
@@ -336,7 +336,7 @@ function path_admin_filter_form($form, &$form_state, $keys = '') {
  * @see path_admin_filter_form_submit_reset()
  */
 function path_admin_filter_form_submit_filter($form, &$form_state) {
-  $form_state['redirect'] = 'admin/config/search/path/list/' . trim($form_state['values']['filter']);
+  $form_state['redirect'] = 'admin/config/search/path/list/' . $form_state['values']['filter'];
 }
 
 /**
diff --git a/core/modules/path/path.module b/core/modules/path/path.module
index 7521dee..e214706 100644
--- a/core/modules/path/path.module
+++ b/core/modules/path/path.module
@@ -155,9 +155,6 @@ function path_form_node_form_alter(&$form, $form_state) {
  */
 function path_form_element_validate($element, &$form_state, $complete_form) {
   if (!empty($form_state['values']['path']['alias'])) {
-    // Trim the submitted value.
-    $alias = trim($form_state['values']['path']['alias']);
-    form_set_value($element['alias'], $alias, $form_state);
     // Node language needs special care. Since the language of the URL alias
     // depends on the node language, and the node language can be switched
     // right within the same form, we need to conditionally overload the
@@ -190,7 +187,7 @@ function path_form_element_validate($element, &$form_state, $complete_form) {
  */
 function path_node_insert(Node $node) {
   if (isset($node->path)) {
-    $alias = trim($node->path['alias']);
+    $alias = $node->path['alias'];
     // Only save a non-empty alias.
     if (!empty($alias)) {
       // Ensure fields for programmatic executions.
@@ -207,7 +204,7 @@ function path_node_insert(Node $node) {
 function path_node_update(Node $node) {
   if (isset($node->path)) {
     $path = $node->path;
-    $alias = trim($path['alias']);
+    $alias = $path['alias'];
     // Delete old alias if user erased it.
     if (!empty($path['pid']) && empty($path['alias'])) {
       drupal_container()->get('path.crud')->delete(array('pid' => $path['pid']));
@@ -272,7 +269,7 @@ function path_form_taxonomy_term_form_alter(&$form, $form_state) {
 function path_taxonomy_term_insert(Term $term) {
   if (isset($term->path)) {
     $path = $term->path;
-    $path['alias'] = trim($path['alias']);
+    $path['alias'] = $path['alias'];
     // Only save a non-empty alias.
     if (!empty($path['alias'])) {
       // Ensure fields for programmatic executions.
@@ -289,7 +286,7 @@ function path_taxonomy_term_insert(Term $term) {
 function path_taxonomy_term_update(Term $term) {
   if (isset($term->path)) {
     $path = $term->path;
-    $path['alias'] = trim($path['alias']);
+    $path['alias'] = $path['alias'];
     // Delete old alias if user erased it.
     if (!empty($path['pid']) && empty($path['alias'])) {
       drupal_container()->get('path.crud')->delete(array('pid' => $path['pid']));
diff --git a/core/modules/search/search.module b/core/modules/search/search.module
index a465e3a..2ea86b8 100644
--- a/core/modules/search/search.module
+++ b/core/modules/search/search.module
@@ -1037,7 +1037,7 @@ function search_box_form_submit($form, &$form_state) {
   $form_id = $form['form_id']['#value'];
   $info = search_get_default_module_info();
   if ($info) {
-    $form_state['redirect'] = 'search/' . $info['path'] . '/' . trim($form_state['values'][$form_id]);
+    $form_state['redirect'] = 'search/' . $info['path'] . '/' . $form_state['values'][$form_id];
   }
   else {
     form_set_error(NULL, t('Search is currently disabled.'), 'error');
diff --git a/core/modules/shortcut/shortcut.admin.inc b/core/modules/shortcut/shortcut.admin.inc
index d46e73b..9f18017 100644
--- a/core/modules/shortcut/shortcut.admin.inc
+++ b/core/modules/shortcut/shortcut.admin.inc
@@ -114,10 +114,6 @@ function shortcut_set_switch($form, &$form_state, $account = NULL) {
  */
 function shortcut_set_switch_validate($form, &$form_state) {
   if ($form_state['values']['set'] == 'new') {
-    // Check to prevent creating a shortcut set with an empty title.
-    if (trim($form_state['values']['label']) == '') {
-      form_set_error('new', t('The new set label is required.'));
-    }
     // Check to prevent a duplicate title.
     if (shortcut_set_title_exists($form_state['values']['label'])) {
       form_set_error('label', t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state['values']['label'])));
diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc
index 37a2bf2..2559aca 100644
--- a/core/modules/system/system.admin.inc
+++ b/core/modules/system/system.admin.inc
@@ -2687,7 +2687,7 @@ function system_date_format_exists($candidate_machine_name) {
  */
 function system_date_formats_form_validate($form, &$form_state) {
   $formats = system_get_date_formats();
-  $format = trim($form_state['values']['date_format_pattern']);
+  $format = $form_state['values']['date_format_pattern'];
 
   // The machine name field should already check to see if the requested
   // machine name is available. Regardless of machine_name or human readable
@@ -2705,7 +2705,7 @@ function system_date_formats_form_submit($form, &$form_state) {
   $pattern_type = $date->canUseIntl() ? DrupalDateTime::INTL : DrupalDateTime::PHP;
   $format = array();
   $format['name'] = check_plain($form_state['values']['date_format_name']);
-  $format['pattern'][$pattern_type] = trim($form_state['values']['date_format_pattern']);
+  $format['pattern'][$pattern_type] = $form_state['values']['date_format_pattern'];
   $format['locales'] = !empty($form_state['values']['date_langcode']) ? $form_state['values']['date_langcode'] : array();
   // Formats created in the UI are not locked.
   $format['locked'] = 0;
diff --git a/core/modules/system/system.module b/core/modules/system/system.module
index c621915..d079aa5 100644
--- a/core/modules/system/system.module
+++ b/core/modules/system/system.module
@@ -324,6 +324,7 @@ function system_element_info() {
   );
   $types['textfield'] = array(
     '#input' => TRUE,
+    '#trim' => TRUE,
     '#size' => 60,
     '#maxlength' => 128,
     '#autocomplete_path' => FALSE,
@@ -334,6 +335,7 @@ function system_element_info() {
   );
   $types['tel'] = array(
     '#input' => TRUE,
+    '#trim' => TRUE,
     '#size' => 30,
     '#maxlength' => 128,
     '#autocomplete_path' => FALSE,
@@ -344,6 +346,7 @@ function system_element_info() {
   );
   $types['email'] = array(
     '#input' => TRUE,
+    '#trim' => TRUE,
     '#size' => 60,
     // user.module is not loaded in case of early bootstrap errors.
     '#maxlength' => defined('EMAIL_MAX_LENGTH') ? EMAIL_MAX_LENGTH : 255,
@@ -356,6 +359,7 @@ function system_element_info() {
   );
   $types['url'] = array(
     '#input' => TRUE,
+    '#trim' => TRUE,
     '#size' => 60,
     '#maxlength' => 255,
     '#autocomplete_path' => FALSE,
@@ -367,6 +371,7 @@ function system_element_info() {
   );
   $types['search'] = array(
     '#input' => TRUE,
+    '#trim' => TRUE,
     '#size' => 60,
     '#maxlength' => 128,
     '#autocomplete_path' => FALSE,
@@ -377,6 +382,7 @@ function system_element_info() {
   );
   $types['number'] = array(
     '#input' => TRUE,
+    '#trim' => TRUE,
     '#step' => 1,
     '#process' => array('ajax_process_form'),
     '#element_validate' => array('form_validate_number'),
@@ -386,6 +392,7 @@ function system_element_info() {
   );
   $types['range'] = array(
     '#input' => TRUE,
+    '#trim' => TRUE,
     '#step' => 1,
     '#min' => 0,
     '#max' => 100,
@@ -397,6 +404,7 @@ function system_element_info() {
   );
   $types['color'] = array(
     '#input' => TRUE,
+    '#trim' => TRUE,
     '#process' => array('ajax_process_form'),
     '#element_validate' => array('form_validate_color'),
     '#pre_render' => array('form_pre_render_color'),
@@ -405,6 +413,7 @@ function system_element_info() {
   );
   $types['machine_name'] = array(
     '#input' => TRUE,
+    '#trim' => TRUE,
     '#default_value' => NULL,
     '#required' => TRUE,
     '#maxlength' => 64,
@@ -432,6 +441,7 @@ function system_element_info() {
   );
   $types['textarea'] = array(
     '#input' => TRUE,
+    '#trim' => TRUE,
     '#cols' => 60,
     '#rows' => 5,
     '#resizable' => 'vertical',
diff --git a/core/modules/system/tests/modules/taxonomy_test/taxonomy_test.module b/core/modules/system/tests/modules/taxonomy_test/taxonomy_test.module
index 2c6c00a..83ec5f7 100644
--- a/core/modules/system/tests/modules/taxonomy_test/taxonomy_test.module
+++ b/core/modules/system/tests/modules/taxonomy_test/taxonomy_test.module
@@ -30,7 +30,7 @@ function taxonomy_test_taxonomy_term_insert(Term $term) {
     db_insert('taxonomy_term_antonym')
       ->fields(array(
         'tid' => $term->tid,
-        'name' => trim($term->antonym)
+        'name' => $term->antonym,
       ))
       ->execute();
   }
@@ -44,7 +44,7 @@ function taxonomy_test_taxonomy_term_update(Term $term) {
     db_merge('taxonomy_term_antonym')
       ->key(array('tid' => $term->tid))
       ->fields(array(
-        'name' => trim($term->antonym)
+        'name' => $term->antonym,
       ))
       ->execute();
   }
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php
index 0d5dfd4..81cd35f 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php
@@ -87,7 +87,7 @@ public function massageFormValues(array $values, array $form, array &$form_state
     foreach($values as $value) {
       // See if the term exists in the chosen vocabulary and return the tid;
       // otherwise, create a new 'autocreate' term for insert/update.
-      if ($possibilities = entity_load_multiple_by_properties('taxonomy_term', array('name' => trim($value), 'vid' => array_keys($vocabularies)))) {
+      if ($possibilities = entity_load_multiple_by_properties('taxonomy_term', array('name' => $value, 'vid' => array_keys($vocabularies)))) {
         $term = array_pop($possibilities);
       }
       else {
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php
index e2b0b59..999beec 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php
@@ -136,9 +136,6 @@ public function validate(array $form, array &$form_state) {
   public function submit(array $form, array &$form_state) {
     $term = parent::submit($form, $form_state);
 
-    // Prevent leading and trailing spaces in term names.
-    $term->name = trim($term->name);
-
     // Convert text_format field into values expected by taxonomy_term_save().
     $description = $form_state['values']['description'];
     $term->description = $description['value'];
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php
index 6785335..b2dca60 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php
@@ -166,9 +166,6 @@ public function submit(array $form, array &$form_state) {
   public function save(array $form, array &$form_state) {
     $vocabulary = $this->getEntity($form_state);
 
-    // Prevent leading and trailing spaces in vocabulary names.
-    $vocabulary->name = trim($vocabulary->name);
-
     switch (taxonomy_vocabulary_save($vocabulary)) {
       case SAVED_NEW:
         drupal_set_message(t('Created new vocabulary %name.', array('%name' => $vocabulary->name)));
diff --git a/core/modules/update/update.settings.inc b/core/modules/update/update.settings.inc
index 0a5e337..9fa6fc9 100644
--- a/core/modules/update/update.settings.inc
+++ b/core/modules/update/update.settings.inc
@@ -66,7 +66,7 @@ function update_settings_validate($form, &$form_state) {
   if (!empty($form_state['values']['update_notify_emails'])) {
     $valid = array();
     $invalid = array();
-    foreach (explode("\n", trim($form_state['values']['update_notify_emails'])) as $email) {
+    foreach (explode("\n", $form_state['values']['update_notify_emails']) as $email) {
       $email = trim($email);
       if (!empty($email)) {
         if (valid_email_address($email)) {
diff --git a/core/modules/user/user.admin.inc b/core/modules/user/user.admin.inc
index 4da13b8..0237871 100644
--- a/core/modules/user/user.admin.inc
+++ b/core/modules/user/user.admin.inc
@@ -1019,9 +1019,6 @@ function user_admin_role($form, $form_state, $role) {
  * Form submit handler for the user_admin_role() form.
  */
 function user_admin_role_submit($form, &$form_state) {
-  // Prevent leading and trailing spaces in role names.
-  $form_state['values']['role']['label'] = trim($form_state['values']['role']['label']);
-
   $role = entity_create('user_role', $form_state['values']['role']);
   if ($role->save() == SAVED_UPDATED) {
     drupal_set_message(t('The role has been renamed.'));
diff --git a/core/modules/user/user.pages.inc b/core/modules/user/user.pages.inc
index 5a872ab..0f3afa3 100644
--- a/core/modules/user/user.pages.inc
+++ b/core/modules/user/user.pages.inc
@@ -78,7 +78,7 @@ function user_pass() {
 }
 
 function user_pass_validate($form, &$form_state) {
-  $name = trim($form_state['values']['name']);
+  $name = $form_state['values']['name'];
   // Try to load by email.
   $users = entity_load_multiple_by_properties('user', array('mail' => $name, 'status' => '1'));
   $account = reset($users);
