Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.721 diff -u -r1.721 comment.module --- modules/comment/comment.module 8 Jun 2009 05:12:15 -0000 1.721 +++ modules/comment/comment.module 9 Jun 2009 12:59:41 -0000 @@ -1780,13 +1780,13 @@ } // Validate the comment's subject. If not specified, extract from comment body. - if (trim($comment_values['subject']) == '') { + if ($comment_values['subject'] == '') { // 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. // Note: format is checked by check_markup(). - $comment_values['subject'] = truncate_utf8(trim(decode_entities(strip_tags(check_markup($comment_values['comment'], $comment_values['comment_format'])))), 29, TRUE); + $comment_values['subject'] = truncate_utf8(decode_entities(strip_tags(check_markup($comment_values['comment'], $comment_values['comment_format']))), 29, TRUE); // Edge cases where the comment body is populated only by HTML tags will // require a default subject. if ($comment_values['subject'] == '') { Index: modules/search/search.module =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.module,v retrieving revision 1.298 diff -u -r1.298 search.module --- modules/search/search.module 3 Jun 2009 06:52:29 -0000 1.298 +++ modules/search/search.module 9 Jun 2009 12:59:44 -0000 @@ -718,7 +718,7 @@ */ function search_query_insert($keys, $option, $value = '') { if (search_query_extract($keys, $option)) { - $keys = trim(preg_replace('/(^| )' . $option . ':[^ ]*/i', '', $keys)); + $keys = preg_replace('/(^| )' . $option . ':[^ ]*/i', '', $keys); } if ($value != '') { $keys .= ' ' . $option . ':' . $value; Index: modules/search/search.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.pages.inc,v retrieving revision 1.9 diff -u -r1.9 search.pages.inc --- modules/search/search.pages.inc 25 May 2009 10:43:53 -0000 1.9 +++ modules/search/search.pages.inc 9 Jun 2009 12:59:44 -0000 @@ -24,7 +24,7 @@ $keys = search_get_keys(); // Only perform search if there is non-whitespace search term: $results = ''; - if (trim($keys)) { + if ($keys) { // Log the search keys: watchdog('search', '%keys (@type).', array('%keys' => $keys, '@type' => module_invoke($type, 'search', 'name')), WATCHDOG_NOTICE, l(t('results'), 'search/' . $type . '/' . $keys)); @@ -126,7 +126,7 @@ * value for the basic search form. */ function search_form_validate($form, &$form_state) { - form_set_value($form['basic']['inline']['processed_keys'], trim($form_state['values']['keys']), $form_state); + form_set_value($form['basic']['inline']['processed_keys'], $form_state['values']['keys'], $form_state); } /** Index: modules/simpletest/tests/form.test =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/tests/form.test,v retrieving revision 1.13 diff -u -r1.13 form.test --- modules/simpletest/tests/form.test 2 Jun 2009 13:47:26 -0000 1.13 +++ modules/simpletest/tests/form.test 9 Jun 2009 12:59:44 -0000 @@ -346,6 +346,48 @@ } /** + * Tests for form elements and their behaviors. + */ +class FormElementTest extends DrupalWebTestCase { + + public static function getInfo() { + return array( + 'name' => t('Form elements test'), + 'description' => t('Tests for form elements and their behaviors'), + 'group' => t('Form API'), + ); + } + + function setUp() { + parent::setUp('form_test'); + } + + /** + * Test that textfield values are trimmed. + */ + function testTextfieldTrim() { + $value = $this->randomName(); + // Create a form that can be processed and contains a textfield. + $form_id = $this->randomName(); + $form_state = form_state_defaults(); + $form['textfield'] = array( + '#type' => 'textfield', + ); + // Set $value with opening and trailing whitespace as input for the textfield. + $form_state['input'] = array( + 'textfield' => ' ' . $value . ' ', + 'form_id' => $form_id, + ); + // Prepare and process the form. + drupal_prepare_form($form_id, $form, $form_state); + drupal_process_form($form_id, $form, $form_state); + // Assure that the resulting form value does not contain the whitespace. + $this->assertEqual($value, $form_state['values']['textfield'], t('Textfield values are trimmed.')); + } + +} + +/** * Test using drupal_form_submit in a batch. */ class FormAPITestCase extends DrupalWebTestCase { Index: modules/menu/menu.module =================================================================== RCS file: /cvs/drupal/drupal/modules/menu/menu.module,v retrieving revision 1.192 diff -u -r1.192 menu.module --- modules/menu/menu.module 27 May 2009 18:33:58 -0000 1.192 +++ modules/menu/menu.module 9 Jun 2009 12:59:42 -0000 @@ -301,11 +301,10 @@ if (!empty($item['delete'])) { menu_link_delete($item['mlid']); } - elseif (trim($item['link_title'])) { - $item['link_title'] = trim($item['link_title']); + elseif ($item['link_title']) { $item['link_path'] = "node/$node->nid"; if (!$item['customized']) { - $item['options']['attributes']['title'] = trim($node->title); + $item['options']['attributes']['title'] = $node->title; } if (!menu_link_save($item)) { drupal_set_message(t('There was an error saving the menu link.'), 'error'); @@ -323,11 +322,10 @@ if (!empty($item['delete'])) { menu_link_delete($item['mlid']); } - elseif (trim($item['link_title'])) { - $item['link_title'] = trim($item['link_title']); + elseif ($item['link_title']) { $item['link_path'] = "node/$node->nid"; if (!$item['customized']) { - $item['options']['attributes']['title'] = trim($node->title); + $item['options']['attributes']['title'] = $node->title; } if (!menu_link_save($item)) { drupal_set_message(t('There was an error saving the menu link.'), 'error'); Index: modules/menu/menu.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/menu/menu.admin.inc,v retrieving revision 1.49 diff -u -r1.49 menu.admin.inc --- modules/menu/menu.admin.inc 7 Jun 2009 02:30:13 -0000 1.49 +++ modules/menu/menu.admin.inc 9 Jun 2009 12:59:42 -0000 @@ -365,7 +365,7 @@ $item['link_path'] = $parsed_link['path']; } } - if (!trim($item['link_path']) || !menu_valid_path($item)) { + if (!$item['link_path'] || !menu_valid_path($item)) { 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']))); } } Index: modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.1069 diff -u -r1.1069 node.module --- modules/node/node.module 5 Jun 2009 21:56:07 -0000 1.1069 +++ modules/node/node.module 9 Jun 2009 12:59:43 -0000 @@ -2392,7 +2392,7 @@ $keys .= ' "' . str_replace('"', ' ', $form_state['values']['phrase']) . '"'; } if (!empty($keys)) { - form_set_value($form['basic']['inline']['processed_keys'], trim($keys), $form_state); + form_set_value($form['basic']['inline']['processed_keys'], $keys, $form_state); } } Index: modules/node/content_types.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/node/content_types.inc,v retrieving revision 1.75 diff -u -r1.75 content_types.inc --- modules/node/content_types.inc 5 Jun 2009 05:28:28 -0000 1.75 +++ modules/node/content_types.inc 9 Jun 2009 12:59:42 -0000 @@ -252,11 +252,11 @@ */ 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(); @@ -289,9 +289,9 @@ $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']; Index: modules/filter/filter.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/filter/filter.admin.inc,v retrieving revision 1.29 diff -u -r1.29 filter.admin.inc --- modules/filter/filter.admin.inc 8 Jun 2009 04:51:45 -0000 1.29 +++ modules/filter/filter.admin.inc 9 Jun 2009 12:59:41 -0000 @@ -183,7 +183,7 @@ */ function filter_admin_format_form_validate($form, &$form_state) { if (!isset($form_state['values']['format'])) { - $name = trim($form_state['values']['name']); + $name = $form_state['values']['name']; $result = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $name))->fetchField(); if ($result) { form_set_error('name', t('Text format names must be unique. A format named %name already exists.', array('%name' => $name))); @@ -197,7 +197,7 @@ function filter_admin_format_form_submit($form, &$form_state) { $format = isset($form_state['values']['format']) ? $form_state['values']['format'] : NULL; $current = filter_list_format($format); - $name = trim($form_state['values']['name']); + $name = $form_state['values']['name']; $cache = TRUE; // Add a new text format. Index: includes/form.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/form.inc,v retrieving revision 1.339 diff -u -r1.339 form.inc --- includes/form.inc 2 Jun 2009 13:47:25 -0000 1.339 +++ includes/form.inc 9 Jun 2009 12:59:40 -0000 @@ -1350,7 +1350,7 @@ if ($edit !== FALSE) { // Equate $edit to the form value to ensure it's marked for // validation. - return str_replace(array("\r", "\n"), '', $edit); + return trim(str_replace(array("\r", "\n"), '', $edit)); } } Index: modules/taxonomy/taxonomy.module =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v retrieving revision 1.477 diff -u -r1.477 taxonomy.module --- modules/taxonomy/taxonomy.module 5 Jun 2009 05:23:57 -0000 1.477 +++ modules/taxonomy/taxonomy.module 9 Jun 2009 12:59:45 -0000 @@ -217,11 +217,6 @@ $vocabulary->nodes = array(); } - if (!empty($vocabulary->name)) { - // Prevent leading and trailing spaces in vocabulary names. - $vocabulary->name = trim($vocabulary->name); - } - if (!isset($vocabulary->module)) { $vocabulary->module = 'taxonomy'; } @@ -348,10 +343,6 @@ * Status constant indicating if term was inserted or updated. */ function taxonomy_term_save($term) { - if ($term->name) { - // Prevent leading and trailing spaces in term names. - $term->name = trim($term->name); - } if (!empty($term->tid) && $term->name) { $status = drupal_write_record('taxonomy_term_data', $term, 'tid'); Index: modules/system/system.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v retrieving revision 1.155 diff -u -r1.155 system.admin.inc --- modules/system/system.admin.inc 8 Jun 2009 04:48:43 -0000 1.155 +++ modules/system/system.admin.inc 9 Jun 2009 12:59:45 -0000 @@ -1129,7 +1129,7 @@ } function system_ip_blocking_form_validate($form, &$form_state) { - $ip = trim($form_state['values']['ip']); + $ip = $form_state['values']['ip']; if (db_query("SELECT * FROM {blocked_ips} WHERE ip = :ip", array(':ip' => $ip))->fetchField()) { form_set_error('ip', t('This IP address is already blocked.')); } @@ -1142,7 +1142,7 @@ } function system_ip_blocking_form_submit($form, &$form_state) { - $ip = trim($form_state['values']['ip']); + $ip = $form_state['values']['ip']; db_insert('blocked_ips') ->fields(array('ip' => $ip)) ->execute(); Index: modules/user/user.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.pages.inc,v retrieving revision 1.39 diff -u -r1.39 user.pages.inc --- modules/user/user.pages.inc 5 Jun 2009 09:26:06 -0000 1.39 +++ modules/user/user.pages.inc 9 Jun 2009 12:59:47 -0000 @@ -42,7 +42,7 @@ } function user_pass_validate($form, &$form_state) { - $name = trim($form_state['values']['name']); + $name = $form_state['values']['name']; // Try to load by email. $users = user_load_multiple(array(), array('mail' => $name, 'status' => '1')); $account = reset($users); Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.1000 diff -u -r1.1000 user.module --- modules/user/user.module 8 Jun 2009 05:00:11 -0000 1.1000 +++ modules/user/user.module 9 Jun 2009 12:59:46 -0000 @@ -521,7 +521,7 @@ $edit['access'] = REQUEST_TIME; } - $edit['mail'] = trim($edit['mail']); $success = drupal_write_record('users', $edit); if (!$success) { // On a failed INSERT some other existing user's uid may be returned. @@ -614,7 +614,6 @@ } function user_validate_mail($mail) { - $mail = trim($mail); if (!$mail) { return t('You must enter an e-mail address.'); } Index: modules/contact/contact.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.admin.inc,v retrieving revision 1.10 diff -u -r1.10 contact.admin.inc --- modules/contact/contact.admin.inc 29 Apr 2009 08:04:23 -0000 1.10 +++ modules/contact/contact.admin.inc 9 Jun 2009 12:59:41 -0000 @@ -97,7 +97,7 @@ function contact_admin_edit_validate($form, &$form_state) { $recipients = explode(',', $form_state['values']['recipients']); foreach ($recipients as $recipient) { - if (!valid_email_address(trim($recipient))) { + if (!valid_email_address($recipient)) { form_set_error('recipients', t('%recipient is an invalid e-mail address.', array('%recipient' => $recipient))); } } @@ -116,7 +116,7 @@ $recipients = explode(',', $form_state['values']['recipients']); foreach ($recipients as $key => $recipient) { // E-mail address validation has already been done in _validate. - $recipients[$key] = trim($recipient); + $recipients[$key] = $recipient; } $form_state['values']['recipients'] = implode(',', $recipients); if (empty($form_state['values']['cid']) || $form_state['values']['contact_op'] == 'add') { Index: modules/path/path.module =================================================================== RCS file: /cvs/drupal/drupal/modules/path/path.module,v retrieving revision 1.158 diff -u -r1.158 path.module --- modules/path/path.module 27 May 2009 18:33:58 -0000 1.158 +++ modules/path/path.module 9 Jun 2009 12:59:43 -0000 @@ -151,7 +151,7 @@ if (user_access('create url aliases') || user_access('administer url aliases')) { if (isset($node->path)) { $language = isset($node->language) ? $node->language : ''; - $node->path = trim($node->path); $has_alias = db_query("SELECT COUNT(dst) FROM {url_alias} WHERE src <> :src AND dst = :dst AND language = :language", array( ':src' => "node/$node->nid", ':dst' => $node->path,