Commit d68fe907 authored by Dries's avatar Dries
Browse files

- Patch #1068016 by franz, karschsp, BartVB, Niklas Fiekas: fixed number field...

- Patch #1068016 by franz, karschsp, BartVB, Niklas Fiekas: fixed number field validation fails to block some invalid input causing later SQL fatal error.
parent fdca0419
......@@ -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;
}
......
......@@ -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.'
);
}
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment