fix: address CodeQL string escaping and regex findings

This commit is contained in:
murashit 2026-07-15 16:05:57 +09:00
parent 805e7bfdf4
commit 4faa986e17
3 changed files with 13 additions and 2 deletions

View file

@ -181,7 +181,7 @@ function normalizedExportedMarkdownLink(link: ParsedMarkdownLink, vaultPath: str
return `[${link.label}](${markdownHref(`${vaultRelative}${parsed.subpath}`)})`;
}
return isFilesystemAbsolutePath(normalizeFilePath(parsed.path)) ? `${link.label} (\`${href.replace(/`/g, "\\`")}\`)` : link.raw;
return isFilesystemAbsolutePath(normalizeFilePath(parsed.path)) ? `${link.label} (${markdownCodeSpan(href)})` : link.raw;
}
function archiveExportShouldKeepAbsolute(vaultRelativePath: string, vaultConfigDir: string | null | undefined): boolean {
@ -192,6 +192,13 @@ function markdownHref(value: string): string {
return /[\s()]/.test(value) ? `<${value}>` : value;
}
function markdownCodeSpan(value: string): string {
let fenceLength = 1;
for (const match of value.matchAll(/`+/g)) fenceLength = Math.max(fenceLength, match[0].length + 1);
const fence = "`".repeat(fenceLength);
return fenceLength === 1 ? `${fence}${value}${fence}` : `${fence} ${value} ${fence}`;
}
function isInsideInlineCode(line: string, offset: number): boolean {
let inCode = false;
for (let index = 0; index < offset; index += 1) {

View file

@ -151,6 +151,7 @@ describe("thread archive export", () => {
"[Vault source line](/Users/showhey/Vault/src/main.ts:12:4#L12)",
"[Vault config](/Users/showhey/Vault/vault-config/plugins/codex-panel/main.js)",
"[External file](/Users/showhey/Repos/project/README.md)",
"[External file with backticks](/Users/showhey/Repos/project/a\\`b``c.md)",
"[Relative](topics/Other.md)",
"[Website](https://example.com/docs)",
"![Image](/Users/showhey/Repos/project/image.png)",
@ -174,6 +175,7 @@ describe("thread archive export", () => {
"[Vault source line](src/main.ts#L12)",
"Vault config (`/Users/showhey/Vault/vault-config/plugins/codex-panel/main.js`)",
"External file (`/Users/showhey/Repos/project/README.md`)",
"External file with backticks (``` /Users/showhey/Repos/project/a\\`b``c.md ```)",
"[Relative](topics/Other.md)",
"[Website](https://example.com/docs)",
"![Image](/Users/showhey/Repos/project/image.png)",

View file

@ -19,7 +19,9 @@ function standaloneRuleBody(selector: string): string {
describe("panel CSS boundaries", () => {
it("defines design tokens on every standalone UI root", () => {
const tokenScope = /^(?<selectors>(?:\.[^{]+,\n)*\.[^{]+) \{/m.exec(styles)?.groups?.["selectors"] ?? "";
const tokenScopeEnd = styles.indexOf(" {");
expect(tokenScopeEnd).toBeGreaterThan(0);
const tokenScope = styles.slice(0, tokenScopeEnd);
expect(tokenScope).toContain(".codex-panel");
expect(tokenScope).toContain(".codex-panel-turn-diff");