Skip to content

Commit

Permalink
fix: Should escape specific content (#506)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackie1210 authored Jun 5, 2023
1 parent 5728f0f commit ddcc610
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"css-box-shadow": "1.0.0-3",
"css-to-react-native": "^3.0.0",
"emoji-regex": "^10.2.1",
"escape-html": "^1.0.3",
"linebreak": "^1.1.0",
"parse-css-color": "^0.2.1",
"postcss-value-parser": "^4.2.0",
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/builder/text.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import escapeHTML from 'escape-html'
import type { ParsedTransformOrigin } from '../transform-origin.js'
import transform from './transform.js'
import { buildXMLString } from '../utils.js'
Expand Down Expand Up @@ -141,11 +142,11 @@ export default function buildText(
fill: style.color,
opacity: opacity !== 1 ? opacity : undefined,
},
content
escapeHTML(content)
) +
(decorationShape || '') +
(filter ? '</g>' : '') +
extra,
shape ? buildXMLString('text', shapeProps, content) : '',
shape ? buildXMLString('text', shapeProps, escapeHTML(content)) : '',
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions test/font.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,24 @@ describe('Font', () => {
expect(toImage(svg, 100)).toMatchImageSnapshot()
})
})

it('should handle escape html when embedFont is false', async () => {
const svg = await satori(
<div
style={{
fontSize: '16px',
}}
>
{`Hello<>&'" world`}
</div>,
{
width: 100,
height: 100,
fonts,
embedFont: false,
}
)

expect(toImage(svg)).toMatchImageSnapshot()
})
})

1 comment on commit ddcc610

@vercel
Copy link

@vercel vercel bot commented on ddcc610 Jun 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.