mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-18 01:42:10 +08:00
fix(ui): use utf-8 encoding for inline SVG icons to support non-latin characters (#7892)
* fix(ui): use utf-8 encoding for inline SVG icons to support non-latin characters * chore(test-item): re-add data-sortable-handle to TestItem box * docs: update changelog
This commit is contained in:
@@ -43,35 +43,26 @@ export const GroupItem = (props: Props) => {
|
||||
>
|
||||
{group?.icon?.trim().startsWith('http') && (
|
||||
<img
|
||||
alt="group icon"
|
||||
alt={group.name}
|
||||
src={iconCachePath === '' ? group.icon : iconCachePath}
|
||||
width="32px"
|
||||
style={{
|
||||
marginRight: '12px',
|
||||
borderRadius: '6px',
|
||||
}}
|
||||
style={{ marginRight: '12px', borderRadius: '6px' }}
|
||||
/>
|
||||
)}
|
||||
{group?.icon?.trim().startsWith('data') && (
|
||||
<img
|
||||
alt="group icon"
|
||||
alt={group.name}
|
||||
src={group.icon}
|
||||
width="32px"
|
||||
style={{
|
||||
marginRight: '12px',
|
||||
borderRadius: '6px',
|
||||
}}
|
||||
style={{ marginRight: '12px', borderRadius: '6px' }}
|
||||
/>
|
||||
)}
|
||||
{group?.icon?.trim().startsWith('<svg') && (
|
||||
<img
|
||||
alt="group icon"
|
||||
src={`data:image/svg+xml;base64,${btoa(group.icon ?? '')}`}
|
||||
alt={group.name}
|
||||
src={`data:image/svg+xml;charset=utf-8,${encodeURIComponent(group.icon)}`}
|
||||
width="32px"
|
||||
style={{
|
||||
marginRight: '12px',
|
||||
borderRadius: '6px',
|
||||
}}
|
||||
style={{ marginRight: '12px', borderRadius: '6px' }}
|
||||
/>
|
||||
)}
|
||||
<ListItemText
|
||||
|
||||
@@ -112,7 +112,7 @@ export const ProxyRender = memo(function ProxyRender(props: RenderProps) {
|
||||
{enable_group_icon && group.icon?.trim().startsWith('http') && (
|
||||
<img
|
||||
src={iconCachePath === '' ? group.icon : iconCachePath}
|
||||
alt="group icon"
|
||||
alt={group.name}
|
||||
width="32px"
|
||||
style={{ marginRight: '12px', borderRadius: '6px' }}
|
||||
/>
|
||||
@@ -120,15 +120,15 @@ export const ProxyRender = memo(function ProxyRender(props: RenderProps) {
|
||||
{enable_group_icon && group.icon?.trim().startsWith('data') && (
|
||||
<img
|
||||
src={group.icon}
|
||||
alt="group icon"
|
||||
alt={group.name}
|
||||
width="32px"
|
||||
style={{ marginRight: '12px', borderRadius: '6px' }}
|
||||
/>
|
||||
)}
|
||||
{enable_group_icon && group.icon?.trim().startsWith('<svg') && (
|
||||
<img
|
||||
src={`data:image/svg+xml;base64,${btoa(group.icon)}`}
|
||||
alt="group icon"
|
||||
src={`data:image/svg+xml;charset=utf-8,${encodeURIComponent(group.icon)}`}
|
||||
alt={group.name}
|
||||
width="32px"
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -72,16 +72,18 @@ export const TestItem = ({ itemData, onEdit, onDelete: removeTest }: Props) => {
|
||||
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
|
||||
{icon.trim().startsWith('http') && (
|
||||
<img
|
||||
alt={name}
|
||||
src={iconCachePath === '' ? icon : iconCachePath}
|
||||
height="40px"
|
||||
/>
|
||||
)}
|
||||
{icon.trim().startsWith('data') && (
|
||||
<img src={icon} height="40px" />
|
||||
<img alt={name} src={icon} height="40px" />
|
||||
)}
|
||||
{icon.trim().startsWith('<svg') && (
|
||||
<img
|
||||
src={`data:image/svg+xml;base64,${btoa(icon)}`}
|
||||
alt={name}
|
||||
src={`data:image/svg+xml;charset=utf-8,${encodeURIComponent(icon)}`}
|
||||
height="40px"
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -75,34 +75,17 @@ export const TestViewer = forwardRef<TestViewerRef, Props>(
|
||||
throw new Error(t('tests.modals.test.errors.urlRequired'))
|
||||
}
|
||||
|
||||
let newList
|
||||
let uid
|
||||
|
||||
if (form.icon && form.icon.startsWith('<svg')) {
|
||||
// 移除 icon 中的注释
|
||||
if (form.icon) {
|
||||
form.icon = form.icon.replace(/<!--[\s\S]*?-->/g, '')
|
||||
}
|
||||
const doc = new DOMParser().parseFromString(
|
||||
form.icon,
|
||||
'image/svg+xml',
|
||||
)
|
||||
if (doc.querySelector('parsererror')) {
|
||||
throw new Error(t('tests.modals.test.errors.invalidSvg'))
|
||||
}
|
||||
}
|
||||
|
||||
if (openType === 'new') {
|
||||
uid = nanoid()
|
||||
const uid = nanoid()
|
||||
const item = { ...form, uid }
|
||||
newList = [...testList, item]
|
||||
const newList = [...testList, item]
|
||||
await patchVerge({ test_list: newList })
|
||||
onChange(uid)
|
||||
} else {
|
||||
if (!form.uid) {
|
||||
throw new Error(t('tests.modals.test.errors.uidMissing'))
|
||||
}
|
||||
uid = form.uid
|
||||
const uid = form.uid
|
||||
|
||||
await patchTestList(uid, form)
|
||||
onChange(uid, form)
|
||||
|
||||
Reference in New Issue
Block a user