Skip to content

Commit 57a4b43

Browse files
committed
Correctly escape quotes in attributes
1 parent ee58d34 commit 57a4b43

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

Diff for: .config/mocha.fast.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"exclude": ["src/test/packages/**", "src/test/slow/**"],
44
"extension": ["ts", "tsx"],
55
"require": ["ts-node/register"],
6-
"spec": ["src/test/**/*.test.ts"],
6+
"spec": ["src/test/**/*.test.ts", "src/test/**/*.test.tsx"],
77
"timeout": 5000,
8-
"watch-files": ["src/**/*.ts"]
8+
"watch-files": ["src/**/*.ts", "src/**/*.tsx"]
99
}

Diff for: .config/mocha.full.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://json.schemastore.org/mocharc.json",
33
"timeout": 0,
4-
"spec": "src/test/**/*.test.ts",
4+
"spec": ["src/test/**/*.test.ts", "src/test/**/*.test.tsx"],
55
"exclude": ["src/test/packages/**"],
66
"require": ["ts-node/register"]
77
}

Diff for: .config/mocha.test-explorer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"package": "./package.json",
66
"require": "ts-node/register",
77
"slow": 500,
8-
"spec": ["src/**/*.test.ts"],
8+
"spec": ["src/**/*.test.ts", "src/**/*.test.tsx"],
99
"timeout": 0,
10-
"watch-files": ["src/**/*.ts"]
10+
"watch-files": ["src/**/*.ts", "src/**/*.tsx"]
1111
}

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- TypeDoc now attempts to correct local anchor links in readme files which are broken by its deconfliction logic, #2413.
1212
- TypeDoc now finds comments on index signatures again, #2414.
1313
- TypeDoc now does a better job of detecting properties when destructured function arguments are used.
14+
- Quotes will now be properly escaped in HTML attribute values.
1415

1516
### Thanks!
1617

Diff for: src/lib/utils/jsx.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export const renderElement = function renderElement(
124124
let html = "";
125125

126126
if (tag !== Fragment) {
127-
if (blockElements.has(tag) && renderPretty) {
127+
if (blockElements.has(tag) && renderPretty && html) {
128128
html += "\n";
129129
}
130130
html += "<";
@@ -141,8 +141,11 @@ export const renderElement = function renderElement(
141141
} else {
142142
html += " ";
143143
html += key;
144-
html += "=";
145-
html += JSON.stringify(val);
144+
html += '="';
145+
html += (
146+
typeof val === "string" ? val : JSON.stringify(val)
147+
).replaceAll('"', "&quot;");
148+
html += '"';
146149
}
147150
}
148151
}

Diff for: src/test/utils/jsx.test.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,9 @@ describe("JSX", () => {
8282
</svg>`.replace(/^\s*|\r?\n/gm, ""),
8383
);
8484
});
85+
86+
it("Properly escapes quotes in html attributes", () => {
87+
const quot = `test"quote`;
88+
equal(renderElement(<div data-foo={quot} />), `<div data-foo="test&quot;quote"></div>`);
89+
});
8590
});

0 commit comments

Comments
 (0)