When the system color scheme changes (e.g. light to dark), the viewer's
change_color_scheme handler updates opts.color_scheme but never updates
opts.is_dark_theme, which remains at its initialization value.
This causes set_color_scheme_class() to use a stale value, so the
calibre-viewer-dark-colors / calibre-viewer-light-colors class on body
never updates. When override_book_colors is set to 'dark', the CSS
override rule only matches when the dark class is present, so the book
content stays in the old theme.
Fix by updating opts.is_dark_theme from the incoming color scheme data
before calling apply_colors() and set_color_scheme_class().
High severity:
- Fix typo normapth -> normpath in srv/content.py (broken endpoint)
- Replace eval() with ast.literal_eval() in catalogs/epub_mobi.py
- Log exceptions in FunctionDispatcher.dispatch instead of swallowing
Medium severity:
- Add path traversal protection to DirContainer read/write/exists
- Fix XPath injection in comments_editor.py merge_contiguous_links
- Use parameterized SQL queries in database2.py library_id setter
- Add safety comment to pickle_loads in utils/serialize.py
When an EPUB contains elements with custom namespace prefixes (e.g.
<vita:metadata>), the remove_namespaces method in the KF8 writer
crashes with `ValueError: Invalid tag name 'vita:'`.
The existing except ValueError block only strips colons from attribute
names but does not handle the tag name itself. This causes the second
makeelement call to raise the same ValueError.
Fix: replace colons with hyphens in the tag name before retrying,
consistent with how colon-containing attributes are already handled.
Since version 9.6.0, pressing `v` in the FTS search result pane results in
the following error:
```
Traceback (most recent call last):
File "/usr/lib/calibre/calibre/gui2/fts/dialog.py", line 32, in view_current_book
if not self.results_panel.view_current_result():
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/usr/lib/calibre/calibre/gui2/fts/search.py", line 1062, in view_current_result
open_book(results, match)
~~~~~~~~~^^^^^^^^^^^^^^^^
File "/usr/lib/calibre/calibre/gui2/fts/search.py", line 115, in open_book
result_dict = results.result_dicts[match_index]
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
TypeError: list indices must be integers or slices, not dict
```
I traced this back to commit b10e56d9e5 (Refactor FTS dialog to allow multiple
result visualisations) which refactored `ResultsView.view_current_result` in
`src/calibre/gui2/fts/search.py` from:
``` python
def view_current_result(self):
idx = self.currentIndex()
if idx.isValid():
results, match = self.m.data_for_index(idx)
if results:
if match is not None:
match = idx.row()
open_book(results, match)
return True
return False
```
to `ResultsPanel.view_current_result`:
``` python
def view_current_result(self):
results, match = self.current_view.current_result()
if results:
open_book(results, match)
return True
return False
```
and `SplitView.current_result`:
``` python
def current_result(self):
idx = self.results_view.currentIndex()
if idx.isValid():
results, match = self.results_view.model().data_for_index(idx)
if match is None:
match = idx.row()
return results, match
return None, None
```
As can be seen in the latter, the condition in the original
`ResultsView.view_current_result`:
``` python
if match is not None:
match = idx.row()
```
has changed to:
``` python
if match is None:
match = idx.row()
```
in `SplitView.current_result` which is causing the error.
This bug is fixed in the current commit.