Skip to content

Commit

Permalink
Issue #1015916 by BTMash, jenlampton, theborg, Aron Novak, christefan…
Browse files Browse the repository at this point in the history
…o, realityloop, xjm, Kevin Hankens: Fixed Image field 'title' allows more data than database column size.
  • Loading branch information
webchick committed Dec 25, 2011
1 parent aa8e8f4 commit 0f48b80
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
5 changes: 3 additions & 2 deletions modules/image/image.field.inc
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ function image_field_widget_process($element, &$form_state, $form) {
'#type' => 'textfield',
'#default_value' => isset($item['alt']) ? $item['alt'] : '',
'#description' => t('This text will be used by screen readers, search engines, or when the image cannot be loaded.'),
'#maxlength' => variable_get('image_alt_length', 80), // See http://www.gawds.org/show.php?contentid=28.
// @see http://www.gawds.org/show.php?contentid=28
'#maxlength' => 128,
'#weight' => -2,
'#access' => (bool) $item['fid'] && $settings['alt_field'],
);
Expand All @@ -412,7 +413,7 @@ function image_field_widget_process($element, &$form_state, $form) {
'#title' => t('Title'),
'#default_value' => isset($item['title']) ? $item['title'] : '',
'#description' => t('The title is used as a tool tip when the user hovers the mouse over the image.'),
'#maxlength' => variable_get('image_title_length', 500),
'#maxlength' => 128,
'#weight' => -1,
'#access' => (bool) $item['fid'] && $settings['title_field'],
);
Expand Down
9 changes: 9 additions & 0 deletions modules/image/image.install
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,15 @@ function image_update_7002(array &$sandbox) {
$sandbox['#finished'] = count($sandbox['tables']) ? ($sandbox['processed'] / $sandbox['total']) : 1;
}

/**
* Remove the variables that set alt and title length since they were not
* used for database column size and could cause PDO exceptions.
*/
function image_update_7003() {
variable_del('image_alt_length');
variable_del('image_title_length');
}

/**
* Implements hook_requirements() to check the PHP GD Library.
*
Expand Down
17 changes: 17 additions & 0 deletions modules/image/image.test
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,23 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
$this->drupalPost('node/' . $nid . '/edit', $edit, t('Save'));
$default_output = theme('image', $image_info);
$this->assertRaw($default_output, t('Image displayed using user supplied alt and title attributes.'));

// Verify that alt/title longer than allowed results in a validation error.
$test_size = 2000;
$max_size = 128;
$edit = array(
$field_name . '[' . LANGUAGE_NONE . '][0][alt]' => $this->randomName($test_size),
$field_name . '[' . LANGUAGE_NONE . '][0][title]' => $this->randomName($test_size),
);
$this->drupalPost('node/' . $nid . '/edit', $edit, t('Save'));
$this->assertRaw(t('Alternate text cannot be longer than %max characters but is currently %length characters long.', array(
'%max' => $max_size,
'%length' => $test_size,
)));
$this->assertRaw(t('Title cannot be longer than %max characters but is currently %length characters long.', array(
'%max' => $max_size,
'%length' => $test_size,
)));
}

/**
Expand Down

0 comments on commit 0f48b80

Please sign in to comment.