From 04e4f258650862c3cd72608f5a15bd24c48534ff Mon Sep 17 00:00:00 2001 From: yusheng chen <55658154+samuel871211@users.noreply.github.com> Date: Mon, 31 Mar 2025 09:55:53 +0800 Subject: [PATCH] feat: add `string.test.ts` (#2557) * feat: add `string.test.ts` refactor: type improvement of variable `match` in file `src/api/transform/o1-format.ts` * feat: add more test with function `removeInvalidChars` --- src/api/transform/o1-format.ts | 2 +- src/utils/string.test.ts | 57 ++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/utils/string.test.ts diff --git a/src/api/transform/o1-format.ts b/src/api/transform/o1-format.ts index 237663cd..b9031b88 100644 --- a/src/api/transform/o1-format.ts +++ b/src/api/transform/o1-format.ts @@ -307,7 +307,7 @@ function parseToolCall(toolName: string, content: string): ToolCall | null { // Parse nested XML elements const paramRegex = /<(\w+)>([\s\S]*?)<\/\1>/gs - let match + let match: RegExpExecArray | null while ((match = paramRegex.exec(innerContent)) !== null) { const [, paramName, paramValue] = match diff --git a/src/utils/string.test.ts b/src/utils/string.test.ts new file mode 100644 index 00000000..f4b8ec44 --- /dev/null +++ b/src/utils/string.test.ts @@ -0,0 +1,57 @@ +import { describe, it } from "mocha" +import "should" +import { fixModelHtmlEscaping, removeInvalidChars } from "./string" + +describe("fixModelHtmlEscaping", () => { + it("should convert > to >", () => { + fixModelHtmlEscaping("foo > bar").should.equal("foo > bar") + }) + + it("should convert < to <", () => { + fixModelHtmlEscaping("foo < bar").should.equal("foo < bar") + }) + + it('should convert " to "', () => { + fixModelHtmlEscaping("foo "bar"").should.equal('foo "bar"') + }) + + it("should convert & to &", () => { + fixModelHtmlEscaping("foo & bar").should.equal("foo & bar") + }) + + it("should convert ' to '", () => { + fixModelHtmlEscaping("foo 'bar'").should.equal("foo 'bar'") + }) + + it("should handle multiple entities in the same string", () => { + fixModelHtmlEscaping("<div>Hello "World" & 'Universe'</div>").should.equal( + "