Skip to content

Commit

Permalink
Add calibredb-sanitize-filter to handle quote
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyanming committed Jul 14, 2024
1 parent 2bcf91e commit bb9cfb5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion calibredb-search.el
Original file line number Diff line number Diff line change
Expand Up @@ -867,11 +867,18 @@ ebook record will be shown.
(defvar calibredb-search-pages 0
"The number of pages in the current search result.")

(defun calibredb-sanitize-filter (filter)
"Sanitize FILTER for use in SQL queries by escaping special characters."
(let ((sanitized filter))
;; Escape single quotes by doubling them
(setq sanitized (replace-regexp-in-string "'" "''" sanitized))
sanitized))

(defun calibredb-search-candidates (filter &rest properties)
"Generate ebook candidate alist.
Argument: FILTER is the filter string.
Argument: PROPERTIES is the addiontal parameters."
(let* ((words (split-string filter " "))
(let* ((words (split-string (calibredb-sanitize-filter filter) " "))
(limit (plist-get properties :limit))
(count (plist-get properties :count))
(page (plist-get properties :page)))
Expand Down

0 comments on commit bb9cfb5

Please sign in to comment.