-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix: handle square bracket HTML entities in Gemini responses #7577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,5 +75,30 @@ describe("Text normalization utilities", () => { | |
| expect(unescapeHtmlEntities("")).toBe("") | ||
| expect(unescapeHtmlEntities(undefined as unknown as string)).toBe(undefined) | ||
| }) | ||
|
|
||
| it("unescapes square bracket entities (numeric)", () => { | ||
| expect(unescapeHtmlEntities("string[]")).toBe("string[]") | ||
| expect(unescapeHtmlEntities("array[0]")).toBe("array[0]") | ||
| expect(unescapeHtmlEntities("matrix[i][j]")).toBe("matrix[i][j]") | ||
| }) | ||
|
|
||
| it("unescapes square bracket entities (named)", () => { | ||
| expect(unescapeHtmlEntities("string[]")).toBe("string[]") | ||
| expect(unescapeHtmlEntities("array[0]")).toBe("array[0]") | ||
| expect(unescapeHtmlEntities("matrix[i][j]")).toBe("matrix[i][j]") | ||
| }) | ||
|
|
||
| it("handles C# array syntax with escaped square brackets", () => { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great test coverage! This test case directly addresses the reported issue with C# array syntax. The test is well-documented with a comment explaining its purpose. |
||
| // Test case based on the reported issue | ||
| const input = "string[] myArray = new string[5];\nmyArray[2] = "hello";" | ||
| const expected = 'string[] myArray = new string[5];\nmyArray[2] = "hello";' | ||
| expect(unescapeHtmlEntities(input)).toBe(expected) | ||
| }) | ||
|
|
||
| it("handles mixed square bracket entities", () => { | ||
| const input = "array[0] and [1]" | ||
| const expected = "array[0] and [1]" | ||
| expect(unescapeHtmlEntities(input)).toBe(expected) | ||
| }) | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,5 +91,9 @@ export function unescapeHtmlEntities(text: string): string { | |
| .replace(/"/g, '"') | ||
| .replace(/'/g, "'") | ||
| .replace(/'/g, "'") | ||
| .replace(/[/g, "[") | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the order of replacements intentional here? I notice that the ampersand replacement is placed last, which seems correct since replacing it first could interfere with other entity replacements. Would it be worth adding a comment explaining why it must be last to prevent future reordering mistakes? |
||
| .replace(/]/g, "]") | ||
| .replace(/[/g, "[") | ||
| .replace(/]/g, "]") | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this PR fixes the square bracket issue, are there other HTML entities that Gemini might escape that we're not handling? For example: parentheses (( and )), curly braces ({ and }), or other mathematical/programming symbols. Might be worth investigating what other entities Gemini commonly escapes in code contexts. |
||
| .replace(/&/g, "&") | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to group all the square bracket tests together in a nested describe block for better organization? This would make the test structure clearer and easier to navigate.