From cadd1b6c111b4b8e9233d9c63b25d14f3e2e953e Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Fri, 13 Aug 2010 04:38:49 +0100 Subject: [PATCH] fix bug #6487 --- src/calibre/gui2/dialogs/config/create_custom_column.py | 8 +++----- src/calibre/library/custom_columns.py | 6 +++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/calibre/gui2/dialogs/config/create_custom_column.py b/src/calibre/gui2/dialogs/config/create_custom_column.py index 34091d893f..fdf093b6d5 100644 --- a/src/calibre/gui2/dialogs/config/create_custom_column.py +++ b/src/calibre/gui2/dialogs/config/create_custom_column.py @@ -100,11 +100,11 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): def accept(self): - col = unicode(self.column_name_box.text()).lower() + col = unicode(self.column_name_box.text()) if not col: return self.simple_error('', _('No lookup name was provided')) - if re.match('^\w*$', col) is None or not col[0].isalpha(): - return self.simple_error('', _('The label must contain only letters, digits and underscores, and start with a letter')) + if re.match('^\w*$', col) is None or not col[0].isalpha() or col.lower() != col: + return self.simple_error('', _('The lookup name must contain only lower case letters, digits and underscores, and start with a letter')) col_heading = unicode(self.column_heading_box.text()) col_type = self.column_types[self.column_type_box.currentIndex()]['datatype'] if col_type == '*text': @@ -130,8 +130,6 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): bad_head = True if bad_head: return self.simple_error('', _('The heading %s is already used')%col_heading) - if ':' in col or ' ' in col or col.lower() != col: - return self.simple_error('', _('The lookup name must be lower case and cannot contain ":"s or spaces')) date_format = {} if col_type == 'datetime': diff --git a/src/calibre/library/custom_columns.py b/src/calibre/library/custom_columns.py index 5b459c6d2a..b8e0f8d3b6 100644 --- a/src/calibre/library/custom_columns.py +++ b/src/calibre/library/custom_columns.py @@ -6,7 +6,7 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import json +import json, re from functools import partial from math import floor @@ -430,6 +430,10 @@ class CustomColumns(object): def create_custom_column(self, label, name, datatype, is_multiple, editable=True, display={}): + if not label: + raise ValueError(_('No label was provided')) + if re.match('^\w*$', label) is None or not label[0].isalpha() or label.lower() != label: + raise ValueError(_('The label must contain only lower case letters, digits and underscores, and start with a letter')) if datatype not in self.CUSTOM_DATA_TYPES: raise ValueError('%r is not a supported data type'%datatype) normalized = datatype not in ('datetime', 'comments', 'int', 'bool',