From db195e6b75a7f4b00a1f1bf1b7200e97dd9c1f56 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 4 Sep 2013 08:26:36 +0530 Subject: [PATCH] newdb: Fix setting author names with | in them Fixes #1220348 [Vertical bar "|" in author name causes ConstraintError](https://bugs.launchpad.net/calibre/+bug/1220348) --- src/calibre/db/tests/writing.py | 5 +++++ src/calibre/db/write.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/calibre/db/tests/writing.py b/src/calibre/db/tests/writing.py index a199da6b28..762517a294 100644 --- a/src/calibre/db/tests/writing.py +++ b/src/calibre/db/tests/writing.py @@ -297,6 +297,11 @@ class WritingTest(BaseTest): ae(sf('tags', {3: ('x', 'X')}), {3}, 'Failed when setting tag twice with different cases') 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): # {{{ diff --git a/src/calibre/db/write.py b/src/calibre/db/write.py index fc8691aa42..ee81659984 100644 --- a/src/calibre/db/write.py +++ b/src/calibre/db/write.py @@ -156,7 +156,7 @@ def get_adapter(name, metadata): if name == 'author_sort': return lambda x: ans(x) or '' 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'}: return lambda x: ans(x) or UNDEFINED_DATE if name == 'series_index':