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