mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Dont allow calibredb to create custom columns with invalid labels. Fixes #6487 (Error: unhandled exception using tag browser to select on --is-multiple type custom column)
This commit is contained in:
commit
d783ff225d
@ -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':
|
||||
|
@ -6,7 +6,7 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user