mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2026-02-10 19:50:28 +08:00
fix: precise proxy group name replacement in smart override rules
This commit is contained in:
parent
3d9507b10c
commit
727eceb0cf
@ -118,18 +118,42 @@ function main(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 更新规则中的代理组引用
|
// 更新规则中的代理组引用
|
||||||
|
// 规则参数列表,这些不是策略组名称
|
||||||
|
const ruleParamsSet = new Set(['no-resolve', 'force-remote-dns', 'prefer-ipv6'])
|
||||||
|
|
||||||
if (config.rules && Array.isArray(config.rules)) {
|
if (config.rules && Array.isArray(config.rules)) {
|
||||||
config.rules = config.rules.map(rule => {
|
config.rules = config.rules.map(rule => {
|
||||||
if (typeof rule === 'string') {
|
if (typeof rule === 'string') {
|
||||||
let updatedRule = rule
|
// 按逗号分割规则,精确匹配策略组名称位置
|
||||||
nameMapping.forEach((newName, oldName) => {
|
const parts = rule.split(',').map(part => part.trim())
|
||||||
// 使用简单的字符串替换,检查是否完全匹配
|
|
||||||
if (updatedRule.includes(oldName)) {
|
if (parts.length >= 2) {
|
||||||
updatedRule = updatedRule.split(oldName).join(newName)
|
// 找到策略组名称的位置
|
||||||
console.log('[Smart Override] Updated rule reference:', oldName, '→', newName)
|
let targetIndex = -1
|
||||||
|
|
||||||
|
// MATCH 规则:MATCH,策略组
|
||||||
|
if (parts[0] === 'MATCH' && parts.length === 2) {
|
||||||
|
targetIndex = 1
|
||||||
|
} else if (parts.length >= 3) {
|
||||||
|
// 其他规则:TYPE,MATCHER,策略组[,参数...]
|
||||||
|
// 策略组通常在第 3 个位置(索引 2),但需要跳过参数
|
||||||
|
for (let i = 2; i < parts.length; i++) {
|
||||||
|
if (!ruleParamsSet.has(parts[i])) {
|
||||||
|
targetIndex = i
|
||||||
|
break
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
return updatedRule
|
}
|
||||||
|
|
||||||
|
// 只替换策略组名称位置
|
||||||
|
if (targetIndex !== -1 && nameMapping.has(parts[targetIndex])) {
|
||||||
|
const oldName = parts[targetIndex]
|
||||||
|
parts[targetIndex] = nameMapping.get(oldName)
|
||||||
|
console.log('[Smart Override] Updated rule reference:', oldName, '→', nameMapping.get(oldName))
|
||||||
|
return parts.join(',')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rule
|
||||||
} else if (typeof rule === 'object' && rule !== null) {
|
} else if (typeof rule === 'object' && rule !== null) {
|
||||||
// 处理对象格式的规则
|
// 处理对象格式的规则
|
||||||
['target', 'proxy'].forEach(field => {
|
['target', 'proxy'].forEach(field => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user