Better regex handling.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Oliver 2026-10-19 12:48:27 +01:00
parent 5447f43f6c
commit c1b081dde8
1 changed files with 6 additions and 1 deletions

View File

@ -24,11 +24,16 @@
[(get-else $ ?e :thumbnail :nil) ?thumbnail] [(get-else $ ?e :thumbnail :nil) ?thumbnail]
[?e :relative-path ?path]]}) [?e :relative-path ?path]]})
(defn escape-regex
"Escape regex special characters so user input is matched literally."
[text]
(str/replace text #"[.*+?^${}()|\[\]\\]" #(str "\\" %)))
(defn db-search-filter (defn db-search-filter
"Add where clauses to the datalog query when supplied" "Add where clauses to the datalog query when supplied"
[{:keys [search tag]}] [{:keys [search tag]}]
(let [re-search (when-not (str/blank? search) (let [re-search (when-not (str/blank? search)
(re-pattern (str "(?i)" search)))] (re-pattern (str "(?i)" (escape-regex search))))]
(cond-> db-search (cond-> db-search
(not (str/blank? tag)) (not (str/blank? tag))
(update-in [:where] #(conj % ['?e :tags tag])) (update-in [:where] #(conj % ['?e :tags tag]))