summaryrefslogtreecommitdiff
path: root/modules/field/field.crud.inc
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-08-10 21:19:42 +0000
committerDries Buytaert <dries@buytaert.net>2009-08-10 21:19:42 +0000
commit4a3dd058b5defa96eedec26fa22c4d332e71df49 (patch)
tree21a9112fcfc237c3838991401649df3baf30fe54 /modules/field/field.crud.inc
parent8b11e7eb6935678e299dd4bbb1bcaa6cb4dc2b7d (diff)
downloadbrdo-4a3dd058b5defa96eedec26fa22c4d332e71df49.tar.gz
brdo-4a3dd058b5defa96eedec26fa22c4d332e71df49.tar.bz2
- Patch #372330 by fgm, yched, et al: better validation of field names.
Diffstat (limited to 'modules/field/field.crud.inc')
-rw-r--r--modules/field/field.crud.inc13
1 files changed, 10 insertions, 3 deletions
diff --git a/modules/field/field.crud.inc b/modules/field/field.crud.inc
index ca19d5ebb..2b71f52f9 100644
--- a/modules/field/field.crud.inc
+++ b/modules/field/field.crud.inc
@@ -208,11 +208,17 @@ function field_create_field($field) {
throw new FieldException('Attempt to create a field with no type.');
}
// Field name cannot contain invalid characters.
- if (preg_match('/[^a-z0-9_]/', $field['field_name'])) {
- throw new FieldException('Attempt to create a field with invalid characters. Only alphanumeric characters and underscores are allowed.');
+ if (!preg_match('/^[_a-z]+[_a-z0-9]*$/', $field['field_name'])) {
+ throw new FieldException('Attempt to create a field with invalid characters. Only lowercase alphanumeric characters and underscores are allowed, and only lowercase letters and underscore are allowed as the first character');
}
- // TODO: check that field_name < 32 chars.
+ // Field name cannot be longer than 32 characters. We use drupal_strlen()
+ // because the DB layer assumes that column widths are given in characters,
+ // not bytes.
+ if (drupal_strlen($field['field_name']) > 32) {
+ throw new FieldException(t('Attempt to create a field with a name longer than 32 characters: %name',
+ array('%name' => $field['field_name'])));
+ }
// Check that the field type is known.
$field_type = field_info_field_types($field['type']);
@@ -233,6 +239,7 @@ function field_create_field($field) {
'locked' => FALSE,
'settings' => array(),
);
+
// Create all per-field-type properties (needed here as long as we have
// settings that impact column definitions).
$field['settings'] += field_info_field_settings($field['type']);