Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .claude/worktrees/agent-ad3369ec
Submodule agent-ad3369ec added at 5f3520
3 changes: 2 additions & 1 deletion src/core/packs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,9 @@ export function createPack(db: Database.Database, options: CreatePackOptions): K
/** Simple glob-style pattern matching (supports * and ** wildcards). */
function matchesExcludePattern(relativePath: string, pattern: string): boolean {
// Escape regex special chars except * and **
// prettier-ignore
const escaped = pattern
.replace(/[.+^${}()|[\]\\]/g, "\\$&")
.replaceAll(/[.+^${}()|[\]\\]/g, String.raw`\$&`)
.replaceAll("**", "\0")
.replaceAll("*", "[^/]*")
.replaceAll("\0", ".*");
Expand Down
3 changes: 2 additions & 1 deletion src/core/parsers/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ export class CsvParser implements DocumentParser {
const colCount = header.length;
const rows = records.slice(1);

// prettier-ignore
const escapeCell = (cell: string): string =>
cell.replaceAll("\\", "\\\\").replaceAll("|", "\\|").replaceAll("\n", " ");
cell.replaceAll("\\", String.raw`\\`).replaceAll("|", String.raw`\|`).replaceAll("\n", " ");

const lines: string[] = [];
lines.push(
Expand Down
9 changes: 5 additions & 4 deletions src/core/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ function isVectorTableError(err: unknown): boolean {

/** Escape LIKE special characters so user input is treated literally. */
export function escapeLikePattern(input: string): string {
// prettier-ignore
return input
.replace(/\\/g, "\\\\")
.replace(/%/g, "\\%")
.replace(/_/g, "\\_")
.replace(/\[/g, "\\[");
.replaceAll("\\", String.raw`\\`)
.replaceAll("%", String.raw`\%`)
.replaceAll("_", String.raw`\_`)
.replaceAll("[", String.raw`\[`);
}

export interface SearchOptions {
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/parsers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ describe("CsvParser", () => {
it("escapes pipe characters in cell values", async () => {
const input = "col1,col2\nfoo|bar,baz";
const result = await parser.parse(Buffer.from(input));
expect(result).toContain("foo\\|bar");
// prettier-ignore
expect(result).toContain(String.raw`foo\|bar`);
});

it("replaces newlines in cell values", async () => {
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/registry/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ describe("registry publish", () => {
addTestRegistry(makeEntry(regName, bareUrl));

const packFile = join(tempDir, "backslash.json");
writeFileSync(packFile, JSON.stringify(makePackJson("foo\\bar")), "utf-8");
// prettier-ignore
writeFileSync(packFile, JSON.stringify(makePackJson(String.raw`foo\bar`)), "utf-8");

await expect(publishPack({ registryName: regName, packFilePath: packFile })).rejects.toThrow(
/path separators/i,
Expand Down
Loading