mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 11:20:07 +08:00
fix: handle undefined html title (#6229)
This commit is contained in:
parent
312b73225a
commit
6cd324f8ba
@ -13,7 +13,6 @@ interface Props {
|
||||
|
||||
const Artifacts: FC<Props> = ({ html }) => {
|
||||
const { t } = useTranslation()
|
||||
const title = extractTitle(html) || 'Artifacts ' + t('chat.artifacts.button.preview')
|
||||
const { openMinapp } = useMinappPopup()
|
||||
|
||||
/**
|
||||
@ -23,6 +22,7 @@ const Artifacts: FC<Props> = ({ html }) => {
|
||||
const path = await window.api.file.create('artifacts-preview.html')
|
||||
await window.api.file.write(path, html)
|
||||
const filePath = `file://${path}`
|
||||
const title = extractTitle(html) || 'Artifacts ' + t('chat.artifacts.button.preview')
|
||||
openMinapp({
|
||||
id: 'artifacts-preview',
|
||||
name: title,
|
||||
|
||||
@ -204,6 +204,11 @@ describe('formats', () => {
|
||||
it('should handle empty string', () => {
|
||||
expect(extractTitle('')).toBeNull()
|
||||
})
|
||||
|
||||
it('should handle undefined', () => {
|
||||
// @ts-ignore for testing
|
||||
expect(extractTitle(undefined)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('removeSvgEmptyLines', () => {
|
||||
|
||||
@ -54,6 +54,8 @@ $$
|
||||
}
|
||||
|
||||
export function extractTitle(html: string): string | null {
|
||||
if (!html) return null
|
||||
|
||||
// 处理标准闭合的标题标签
|
||||
const titleRegex = /<title>(.*?)<\/title>/i
|
||||
const match = html.match(titleRegex)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user