newdb: Fix setting author names with | in them

Fixes #1220348 [Vertical bar "|" in author name causes ConstraintError](https://bugs.launchpad.net/calibre/+bug/1220348)
This commit is contained in:
Kovid Goyal 2013-09-04 08:26:36 +05:30
parent cca7c89f24
commit db195e6b75
2 changed files with 6 additions and 1 deletions

View File

@ -297,6 +297,11 @@ class WritingTest(BaseTest):
ae(sf('tags', {3: ('x', 'X')}), {3}, 'Failed when setting tag twice with different cases') ae(sf('tags', {3: ('x', 'X')}), {3}, 'Failed when setting tag twice with different cases')
ae(('x',), cache.field_for('tags', 3)) ae(('x',), cache.field_for('tags', 3))
# Test setting of authors with | in their names (for legacy database
# format compatibility | is replaced by ,)
ae(sf('authors', {3: ('Some| Author',)}), {3})
ae(('Some, Author',), cache.field_for('authors', 3))
# }}} # }}}
def test_dirtied(self): # {{{ def test_dirtied(self): # {{{

View File

@ -156,7 +156,7 @@ def get_adapter(name, metadata):
if name == 'author_sort': if name == 'author_sort':
return lambda x: ans(x) or '' return lambda x: ans(x) or ''
if name == 'authors': if name == 'authors':
return lambda x: ans(x) or (_('Unknown'),) return lambda x: tuple(y.replace('|', ',') for y in ans(x)) or (_('Unknown'),)
if name in {'timestamp', 'last_modified'}: if name in {'timestamp', 'last_modified'}:
return lambda x: ans(x) or UNDEFINED_DATE return lambda x: ans(x) or UNDEFINED_DATE
if name == 'series_index': if name == 'series_index':