context-mode 1.0.144 → 1.0.146

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/store.js CHANGED
@@ -524,7 +524,7 @@ export class ContentStore {
524
524
  highlight(chunks, 1, char(2), char(3)) AS highlighted
525
525
  FROM chunks
526
526
  JOIN sources ON sources.id = chunks.source_id
527
- WHERE chunks MATCH ? AND sources.label LIKE ?
527
+ WHERE chunks MATCH ? AND sources.label LIKE ? ESCAPE '\\'
528
528
  ORDER BY rank
529
529
  LIMIT ?
530
530
  `);
@@ -569,7 +569,7 @@ export class ContentStore {
569
569
  highlight(chunks_trigram, 1, char(2), char(3)) AS highlighted
570
570
  FROM chunks_trigram
571
571
  JOIN sources ON sources.id = chunks_trigram.source_id
572
- WHERE chunks_trigram MATCH ? AND sources.label LIKE ?
572
+ WHERE chunks_trigram MATCH ? AND sources.label LIKE ? ESCAPE '\\'
573
573
  ORDER BY rank
574
574
  LIMIT ?
575
575
  `);
@@ -615,7 +615,7 @@ export class ContentStore {
615
615
  highlight(chunks, 1, char(2), char(3)) AS highlighted
616
616
  FROM chunks
617
617
  JOIN sources ON sources.id = chunks.source_id
618
- WHERE chunks MATCH ? AND sources.label LIKE ? AND chunks.content_type = ?
618
+ WHERE chunks MATCH ? AND sources.label LIKE ? ESCAPE '\\' AND chunks.content_type = ?
619
619
  ORDER BY rank
620
620
  LIMIT ?
621
621
  `);
@@ -660,7 +660,7 @@ export class ContentStore {
660
660
  highlight(chunks_trigram, 1, char(2), char(3)) AS highlighted
661
661
  FROM chunks_trigram
662
662
  JOIN sources ON sources.id = chunks_trigram.source_id
663
- WHERE chunks_trigram MATCH ? AND sources.label LIKE ? AND chunks_trigram.content_type = ?
663
+ WHERE chunks_trigram MATCH ? AND sources.label LIKE ? ESCAPE '\\' AND chunks_trigram.content_type = ?
664
664
  ORDER BY rank
665
665
  LIMIT ?
666
666
  `);
@@ -859,7 +859,19 @@ export class ContentStore {
859
859
  }));
860
860
  }
861
861
  #sourceFilterParam(source, sourceMatchMode) {
862
- return sourceMatchMode === "exact" ? source : `%${source}%`;
862
+ if (sourceMatchMode === "exact")
863
+ return source;
864
+ // Escape SQLite LIKE metacharacters so user-supplied source labels
865
+ // containing `_`, `%`, or `\` are matched literally rather than as
866
+ // wildcards. Backslash must be replaced first (otherwise subsequent
867
+ // escapes would themselves be re-escaped). Paired with `ESCAPE '\'`
868
+ // in the four prepared LIKE statements (#stmtSearchPorter*,
869
+ // #stmtSearchTrigram*). Regression: #646.
870
+ const escaped = source
871
+ .replace(/\\/g, "\\\\")
872
+ .replace(/%/g, "\\%")
873
+ .replace(/_/g, "\\_");
874
+ return `%${escaped}%`;
863
875
  }
864
876
  search(query, limit = 3, source, mode = "AND", contentType, sourceMatchMode = "like") {
865
877
  const sanitized = sanitizeQuery(query, mode);