fix(v2): escape alt text in img tag (#3757)

This commit is contained in:
Alexey Pyltsyn 2020-11-16 17:21:36 +03:00 committed by GitHub
parent 3ad453932f
commit 311be6e71a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 1 deletions

View file

@ -18,6 +18,8 @@ exports[`transformImage plugin transform md images to <img /> 1`] = `
<img alt={\\"img\\"} src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!./img.png\\").default} title=\\"Title\\" /> <img alt={\\"img\\"} src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/fixtures/img.png\\").default} />
<img alt={\\"img with &quot;quotes&quot;\\"} src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!./img.png\\").default} title=\\"&#39;Quoted&#39; title\\" />
## Heading
\`\`\`md

View file

@ -6,6 +6,8 @@
![img](./img.png 'Title') ![img](/img.png)
![img with "quotes"](./img.png ''Quoted' title')
## Heading
```md

View file

@ -19,7 +19,7 @@ const {
const createJSX = (node, pathUrl) => {
node.type = 'jsx';
node.value = `<img ${node.alt ? `alt={"${node.alt}"} ` : ''}${
node.value = `<img ${node.alt ? `alt={"${escapeHtml(node.alt)}"} ` : ''}${
node.url
? `src={require("${inlineMarkdownImageFileLoader}${pathUrl}").default}`
: ''