mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-06 21:35:52 +08:00
fix: regex pattern error when update manual blacklist (#9871)
This commit is contained in:
parent
128b1fe9bc
commit
9ff4acf092
@ -71,15 +71,27 @@ const BlacklistSettings: FC = () => {
|
|||||||
|
|
||||||
function updateManualBlacklist(blacklist: string) {
|
function updateManualBlacklist(blacklist: string) {
|
||||||
const blacklistDomains = blacklist.split('\n').filter((url) => url.trim() !== '')
|
const blacklistDomains = blacklist.split('\n').filter((url) => url.trim() !== '')
|
||||||
|
|
||||||
const validDomains: string[] = []
|
const validDomains: string[] = []
|
||||||
const hasError = blacklistDomains.some((domain) => {
|
const hasError = blacklistDomains.some((domain) => {
|
||||||
const parsed = parseMatchPattern(domain.trim())
|
const trimmedDomain = domain.trim()
|
||||||
if (parsed === null) {
|
// 正则表达式
|
||||||
return true // 有错误
|
if (trimmedDomain.startsWith('/') && trimmedDomain.endsWith('/')) {
|
||||||
|
try {
|
||||||
|
const regexPattern = trimmedDomain.slice(1, -1)
|
||||||
|
new RegExp(regexPattern, 'i')
|
||||||
|
validDomains.push(trimmedDomain)
|
||||||
|
return false
|
||||||
|
} catch (error) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const parsed = parseMatchPattern(trimmedDomain)
|
||||||
|
if (parsed === null) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
validDomains.push(trimmedDomain)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
validDomains.push(domain.trim())
|
|
||||||
return false
|
|
||||||
})
|
})
|
||||||
|
|
||||||
setErrFormat(hasError)
|
setErrFormat(hasError)
|
||||||
@ -237,7 +249,9 @@ const BlacklistSettings: FC = () => {
|
|||||||
<Button onClick={() => updateManualBlacklist(blacklistInput)} style={{ marginTop: 10 }}>
|
<Button onClick={() => updateManualBlacklist(blacklistInput)} style={{ marginTop: 10 }}>
|
||||||
{t('common.save')}
|
{t('common.save')}
|
||||||
</Button>
|
</Button>
|
||||||
{errFormat && <Alert message={t('settings.tool.websearch.blacklist_tooltip')} type="error" />}
|
{errFormat && (
|
||||||
|
<Alert style={{ marginTop: 10 }} message={t('settings.tool.websearch.blacklist_tooltip')} type="error" />
|
||||||
|
)}
|
||||||
</SettingGroup>
|
</SettingGroup>
|
||||||
<SettingGroup theme={theme}>
|
<SettingGroup theme={theme}>
|
||||||
<SettingTitle>
|
<SettingTitle>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user