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

test(knowledge-base): cover DOCX text extraction edge cases (#1704)

Michael D'Angelo58433cd3683f
diff --git a/sdk/typescript/tests-ts/knowledge-base.test.ts b/sdk/typescript/tests-ts/knowledge-base.test.ts
index 7baee8b19..f2683ef29 100644
--- a/sdk/typescript/tests-ts/knowledge-base.test.ts
+++ b/sdk/typescript/tests-ts/knowledge-base.test.ts
@@ -652,6 +652,47 @@ describe("scan knowledge bases", () => {
expect(Object.values(snapshot.documents)).toEqual([expected]);
});
+ test.each([
+ [
+ "CDATA between text nodes",
+ "Require <![CDATA[authorization]]> before access",
+ "Require authorization before access",
+ ],
+ [
+ "comments containing markup",
+ "Require<!-- x > hidden <w:tab/> --> authorization",
+ "Require authorization",
+ ],
+ [
+ "processing instructions",
+ "Require<?note x > hidden?> authorization",
+ "Require authorization",
+ ],
+ ])("preserves DOCX text with %s", async (_name, xml, expected) => {
+ const root = await temporaryDirectory();
+ const source = join(root, "guide.docx");
+ await writeFile(source, docx(xml));
+
+ const prepared = await prepareKnowledgeBase([source]);
+ temporaryDirectories.track(prepared.path);
+ expect(await extractedDocuments(prepared.path)).toEqual([`${expected}\n`]);
+ });
+
+ test("keeps quoted XML attributes out of DOCX text", async () => {
+ const root = await temporaryDirectory();
+ const source = join(root, "guide.docx");
+ await writeFile(
+ source,
+ docx("Authorization", "Review permissions", '<w:br note="x > y"/>'),
+ );
+
+ const prepared = await prepareKnowledgeBase([source]);
+ temporaryDirectories.track(prepared.path);
+ expect(await extractedDocuments(prepared.path)).toEqual([
+ "Authorization\nReview permissions\n",
+ ]);
+ });
+
test.each([
["preparation", prepareKnowledgeBase],
["snapshot extraction", readKnowledgeBaseSnapshot],