diff --git a/.config/mocha.fast.json b/.config/mocha.fast.json index 9e6866d3a..bc6b6d20f 100644 --- a/.config/mocha.fast.json +++ b/.config/mocha.fast.json @@ -3,7 +3,7 @@ "exclude": ["src/test/packages/**", "src/test/slow/**"], "extension": ["ts", "tsx"], "require": ["ts-node/register"], - "spec": ["src/test/**/*.test.ts"], + "spec": ["src/test/**/*.test.ts", "src/test/**/*.test.tsx"], "timeout": 5000, - "watch-files": ["src/**/*.ts"] + "watch-files": ["src/**/*.ts", "src/**/*.tsx"] } diff --git a/.config/mocha.full.json b/.config/mocha.full.json index 6636bdce8..641407a28 100644 --- a/.config/mocha.full.json +++ b/.config/mocha.full.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/mocharc.json", "timeout": 0, - "spec": "src/test/**/*.test.ts", + "spec": ["src/test/**/*.test.ts", "src/test/**/*.test.tsx"], "exclude": ["src/test/packages/**"], "require": ["ts-node/register"] } diff --git a/.config/mocha.test-explorer.json b/.config/mocha.test-explorer.json index f4b40c445..980a101b0 100644 --- a/.config/mocha.test-explorer.json +++ b/.config/mocha.test-explorer.json @@ -5,7 +5,7 @@ "package": "./package.json", "require": "ts-node/register", "slow": 500, - "spec": ["src/**/*.test.ts"], + "spec": ["src/**/*.test.ts", "src/**/*.test.tsx"], "timeout": 0, - "watch-files": ["src/**/*.ts"] + "watch-files": ["src/**/*.ts", "src/**/*.tsx"] } diff --git a/CHANGELOG.md b/CHANGELOG.md index cf45bd22d..912833465 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - TypeDoc now attempts to correct local anchor links in readme files which are broken by its deconfliction logic, #2413. - TypeDoc now finds comments on index signatures again, #2414. - TypeDoc now does a better job of detecting properties when destructured function arguments are used. +- Quotes will now be properly escaped in HTML attribute values. ### Thanks! diff --git a/src/lib/utils/jsx.ts b/src/lib/utils/jsx.ts index ffe06102e..019ea39bf 100644 --- a/src/lib/utils/jsx.ts +++ b/src/lib/utils/jsx.ts @@ -124,7 +124,7 @@ export const renderElement = function renderElement( let html = ""; if (tag !== Fragment) { - if (blockElements.has(tag) && renderPretty) { + if (blockElements.has(tag) && renderPretty && html) { html += "\n"; } html += "<"; @@ -141,8 +141,11 @@ export const renderElement = function renderElement( } else { html += " "; html += key; - html += "="; - html += JSON.stringify(val); + html += '="'; + html += ( + typeof val === "string" ? val : JSON.stringify(val) + ).replaceAll('"', """); + html += '"'; } } } diff --git a/src/test/utils/jsx.test.tsx b/src/test/utils/jsx.test.tsx index a6ce365f5..214521a6f 100644 --- a/src/test/utils/jsx.test.tsx +++ b/src/test/utils/jsx.test.tsx @@ -82,4 +82,9 @@ describe("JSX", () => { `.replace(/^\s*|\r?\n/gm, ""), ); }); + + it("Properly escapes quotes in html attributes", () => { + const quot = `test"quote`; + equal(renderElement(
), `
`); + }); });