mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-08-22 03:18:54 +08:00
fix(sanitizer): strip alt text from reference-style markdown images (#1488)
stripMarkdownImageAltText removed alt text from inline images
() but not reference-style images (![alt][ref]), because the
regex requires the "](" of the inline form. Alt text is a
hidden-instruction channel that reaches the prompt via sanitizeContent,
so the reference-style form let it survive.
Add a matching replace for the reference-style form (![alt][ref] ->
![][ref]), preserving the [ref] label so the image definition still
resolves. Adds regression tests.
Co-authored-by: Contributor <you@example.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Contributor
Claude Opus 4.8
parent
e64308ff97
commit
5f509a1c1f
@@ -59,6 +59,22 @@ describe("stripMarkdownImageAltText", () => {
|
||||
it("should handle empty alt text", () => {
|
||||
expect(stripMarkdownImageAltText("")).toBe("");
|
||||
});
|
||||
|
||||
it("should remove alt text from reference-style images", () => {
|
||||
expect(stripMarkdownImageAltText("![example alt text][img1]")).toBe(
|
||||
"![][img1]",
|
||||
);
|
||||
expect(
|
||||
stripMarkdownImageAltText("Text ![description][ref] more text"),
|
||||
).toBe("Text ![][ref] more text");
|
||||
});
|
||||
|
||||
it("should preserve the reference label of a reference-style image", () => {
|
||||
// the [ref] label must survive so the image definition still resolves;
|
||||
// only the alt text (the injection channel) is removed
|
||||
expect(stripMarkdownImageAltText("![alt][my-ref]")).toBe("![][my-ref]");
|
||||
expect(stripMarkdownImageAltText("![][keep]")).toBe("![][keep]");
|
||||
});
|
||||
});
|
||||
|
||||
describe("stripMarkdownLinkTitles", () => {
|
||||
|
||||
Reference in New Issue
Block a user