From 6adf8ca0c26a9bc2c6cdc88be89974f7d8d096ad Mon Sep 17 00:00:00 2001 From: webchick Date: Mon, 30 Apr 2012 21:53:37 -0700 Subject: [PATCH] Issue #1262592 by jmarkel, pingers, marcingy: Fixed numeric names fail image creation. --- modules/image/image.module | 5 ++++- modules/image/image.test | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/image/image.module b/modules/image/image.module index 3bf4b6861fe..dda4d9df915 100644 --- a/modules/image/image.module +++ b/modules/image/image.module @@ -749,7 +749,10 @@ function image_style_options($include_empty = TRUE) { if ($include_empty && !empty($styles)) { $options[''] = t(''); } - $options = array_merge($options, drupal_map_assoc(array_keys($styles))); + // Use the array concatenation operator '+' here instead of array_merge(), + // because the latter loses the datatype of the array keys, turning + // associative string keys into numeric ones without warning. + $options = $options + drupal_map_assoc(array_keys($styles)); if (empty($options)) { $options[''] = t('No defined styles'); } diff --git a/modules/image/image.test b/modules/image/image.test index be6882764e9..de3c1b2e1c9 100644 --- a/modules/image/image.test +++ b/modules/image/image.test @@ -354,6 +354,21 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase { return count(file_scan_directory('public://styles/' . $style['name'], '/.*/')); } + /** + * Test creating an image style with a numeric name and ensuring it can be + * applied to an image. + */ + function testNumericStyleName() { + $style_name = rand(); + $edit = array( + 'name' => $style_name, + ); + $this->drupalPost('admin/config/media/image-styles/add', $edit, t('Create new style')); + $this->assertRaw(t('Style %name was created.', array('%name' => $style_name)), t('Image style successfully created.')); + $options = image_style_options(); + $this->assertTrue(array_key_exists($style_name, $options), t('Array key %key exists.', array('%key' => $style_name))); + } + /** * General test to add a style, add/remove/edit effects to it, then delete it. */