Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

fix(patch): stop source excerpts at the end of the file (#2015)

1232e9d3ee369a
diff --git a/sdk/typescript/src/patch-tui.tsx b/sdk/typescript/src/patch-tui.tsx
index 0ab2c1f06..6d95ab3a5 100644
--- a/sdk/typescript/src/patch-tui.tsx
+++ b/sdk/typescript/src/patch-tui.tsx
@@ -174,6 +174,7 @@ function locationSource(
}
const source = readFileSync(path, "utf8").split(/\r?\n/u);
+ if (source.at(-1) === "") source.pop();
const first = Math.max(0, location.startLine - 4);
const last = Math.min(
source.length,
diff --git a/sdk/typescript/tests-ts/patch-tui.test.ts b/sdk/typescript/tests-ts/patch-tui.test.ts
index 4f883eab2..f10898d9a 100644
--- a/sdk/typescript/tests-ts/patch-tui.test.ts
+++ b/sdk/typescript/tests-ts/patch-tui.test.ts
@@ -187,6 +187,7 @@ describe("interactive patch finding browser", () => {
'const token = "sk-proj-SYNTHETIC_KEY_123";',
].join("\n"),
);
+ await writeFile(join(repository, "eof.ts"), "\r\n".repeat(10));
const outside = join(directory, "outside.ts");
await writeFile(outside, "OUTSIDE_PRIVATE_SOURCE");
await symlink(outside, join(repository, "src", "outside-link.ts"));
@@ -199,6 +200,7 @@ describe("interactive patch finding browser", () => {
endLine: 6,
role: "sink",
},
+ { path: "eof.ts", startLine: 10 },
{ path: "../outside.ts", startLine: 1 },
{ path: "src/outside-link.ts", startLine: 1 },
];
@@ -226,6 +228,8 @@ describe("interactive patch finding browser", () => {
expect(reviewed).toContain("includeDeleted: false");
expect(reviewed).toContain("7 │ audit.record(tenant);");
expect(reviewed).toContain('const token = "sk-proj-SYNTHETIC_KEY_123";');
+ expect(reviewed).toContain("› 10 │");
+ expect(reviewed).not.toContain(" 11 │");
expect(reviewed).toContain("../outside.ts:1");
expect(reviewed).toContain("src/outside-link.ts:1");
expect(reviewed).not.toContain("OUTSIDE_PRIVATE_SOURCE");