summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDries2012-02-07 14:55:09 -0500
committerDries2012-02-07 14:55:09 -0500
commitd68fe9071d059e36426a468c5121281fb259de42 (patch)
tree2c9affce1dab88a69277a8eee84522eb113e84b1
parentfdca0419a524917d0d8b912615fe1fe366756417 (diff)
- Patch #1068016 by franz, karschsp, BartVB, Niklas Fiekas: fixed number field validation fails to block some invalid input causing later SQL fatal error.
-rw-r--r--core/modules/field/modules/number/number.module4
-rw-r--r--core/modules/field/modules/number/number.test22
2 files changed, 24 insertions, 2 deletions
diff --git a/core/modules/field/modules/number/number.module b/core/modules/field/modules/number/number.module
index 87e2d3a..d00c55f 100644
--- a/core/modules/field/modules/number/number.module
+++ b/core/modules/field/modules/number/number.module
@@ -377,12 +377,12 @@ function number_field_widget_validate($element, &$form_state) {
switch ($type) {
case 'float':
case 'decimal':
- $regexp = '@[^-0-9\\' . $field['settings']['decimal_separator'] . ']@';
+ $regexp = '@([^-0-9\\' . $field['settings']['decimal_separator'] . '])|(.-)@';
$message = t('Only numbers and the decimal separator (@separator) allowed in %field.', array('%field' => $instance['label'], '@separator' => $field['settings']['decimal_separator']));
break;
case 'integer':
- $regexp = '@[^-0-9]@';
+ $regexp = '@([^-0-9])|(.-)@';
$message = t('Only numbers are allowed in %field.', array('%field' => $instance['label']));
break;
}
diff --git a/core/modules/field/modules/number/number.test b/core/modules/field/modules/number/number.test
index e96be42..5488e66 100644
--- a/core/modules/field/modules/number/number.test
+++ b/core/modules/field/modules/number/number.test
@@ -92,6 +92,28 @@ class NumberFieldTestCase extends DrupalWebTestCase {
t('Correctly failed to save decimal value with more than one decimal point.')
);
}
+
+ // Try to create entries with minus sign not in the first position
+ $wrong_entries = array(
+ '3-3',
+ '4-',
+ '1.3-',
+ '1.2-4',
+ '-10-10',
+ );
+
+ foreach ($wrong_entries as $wrong_entry) {
+ $this->drupalGet('test-entity/add/test-bundle');
+ $edit = array(
+ "{$this->field['field_name']}[$langcode][0][value]" => $wrong_entry,
+ );
+ $this->drupalPost(NULL, $edit, t('Save'));
+ $this->assertText(
+ t('Only numbers and the decimal separator (@separator) allowed in ',
+ array('@separator' => $this->field['settings']['decimal_separator'])),
+ 'Correctly failed to save decimal value with minus sign in the wrong position.'
+ );
+ }
}
/**