mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-08-22 03:18:54 +08:00
fix(sanitizer): match attribute quotes by type to avoid mangling content (#1371)
stripHiddenAttributes used the pattern `["'][^"']*["']` for each quoted attribute, which matches an opening quote of either type and stops at the first quote of either type. When a value contained the other quote character — e.g. an apostrophe inside a double-quoted attribute like `title="We'll do it"` — the match terminated at the apostrophe, so the wrong span was removed and the surrounding text was corrupted (e.g. `<Tooltip title="We'll do it" placement="top">` became `<Tooltipll do it" placement="top">`). This surfaced via the github_inline_comment MCP tool: suggestion blocks whose code lines contain quotes were mangled before posting (#1366). Match each quoted form per quote type (`"[^"]*"` and `'[^']*'`), mirroring stripMarkdownLinkTitles, so a value may freely contain the other quote character. The unquoted fallback is unchanged. Closes #1366 Co-authored-by: bymle <229636660+bymle@users.noreply.github.com>
This commit is contained in:
@@ -131,6 +131,21 @@ describe("stripHiddenAttributes", () => {
|
||||
),
|
||||
).toBe('<img src="pic.jpg" class="image">');
|
||||
});
|
||||
|
||||
it("should not corrupt content when an attribute value contains the other quote type", () => {
|
||||
// Regression for #1366: an apostrophe inside a double-quoted attribute
|
||||
// (or a double quote inside a single-quoted attribute) must not cause the
|
||||
// closing quote to be mismatched, which previously mangled later text.
|
||||
expect(
|
||||
stripHiddenAttributes(`<Tooltip title="We'll do it" placement="top">`),
|
||||
).toBe('<Tooltip placement="top">');
|
||||
expect(
|
||||
stripHiddenAttributes(`<img alt="Bob's avatar" src="pic.jpg">`),
|
||||
).toBe('<img src="pic.jpg">');
|
||||
expect(stripHiddenAttributes(`<div title='say "hi"'>Content</div>`)).toBe(
|
||||
"<div>Content</div>",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("normalizeHtmlEntities", () => {
|
||||
|
||||
Reference in New Issue
Block a user