File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -342,7 +342,7 @@ DROP TRIGGER IF EXISTS blocks_au;
342342 (and (re-find #"[^\w\s ]" q)
343343 (or (not (some #(string/includes? match-input %) [" AND" " OR" " NOT" ]))
344344 (string/includes? q " /" ))) ; punctuations
345- (str " \" " match-input " \" *" )
345+ (str " \" " ( string/replace match-input " \" " " \"\" " ) " \" *" )
346346 (not= q match-input)
347347 (string/replace match-input " ," " " )
348348 :else
Original file line number Diff line number Diff line change 209209 (is (some? result))
210210 (is (empty? result)))))
211211
212+ (deftest search-blocks-escapes-quotes-for-fts
213+ (testing " user quote characters are escaped before SQLite FTS receives them"
214+ (let [fts-binds (atom [])
215+ db #js {:exec (fn [opts]
216+ (let [sql (aget opts " sql" )
217+ bind (js->clj (aget opts " bind" ))]
218+ (when (string/includes? sql " title match ?" )
219+ (swap! fts-binds conj (first bind)))
220+ #js []))}]
221+ (with-redefs [search/combine-results (fn [_db results] results)
222+ search/search-result->block-result
223+ (fn [_conn _q _code-class _option result]
224+ result)]
225+ (is (empty? (search/search-blocks (atom :large-db ) db " \" " {:limit 10 })))
226+ (is (empty? (search/search-blocks (atom :large-db ) db " foo \" bar" {:limit 10 })))
227+ (is (= [" \"\"\"\" *" " \" foo \"\" bar\" *" ] @fts-binds))))))
228+
212229(deftest search-blocks-large-graph-benchmark-regression
213230 (testing " cmd-k and autocomplete queries must not scan the full Datascript graph while typing"
214231 (let [calls (atom [])
You can’t perform that action at this time.
0 commit comments