fix: the problem that the DNS override nameserver-policy field cannot correctly recognize multiple writing methods (#4011)
* fix: the problem that the DNS override nameserver-policy field cannot correctly recognize multiple writing methods * update logs * fix-dns-viewer.tsx
This commit is contained in:
@@ -10,7 +10,8 @@
|
||||
- 修复导入订阅时非 http 协议链接被错误尝试导入
|
||||
- 修复切换节点后页面长时间 loading 及缓存过期导致的数据不同步问题
|
||||
- 修复将快捷键名称更名为 `Clash Verge`之后无法删除图标和无法删除注册表
|
||||
- 修复`DNS`覆写服务器支持默认留空
|
||||
- 修复`DNS`覆写 `fallback` `proxy server` `nameserver` `direct Nameserver` 字段支持留空
|
||||
- 修复`DNS`覆写 `nameserver-policy` 字段无法正确识别 `geo` 库
|
||||
|
||||
### ✨ 新增功能
|
||||
|
||||
|
||||
@@ -332,54 +332,51 @@ export const DnsViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 格式化nameserver-policy为字符串
|
||||
const formatNameserverPolicy = (policy: any): string => {
|
||||
if (!policy) return "";
|
||||
|
||||
let result: string[] = [];
|
||||
|
||||
Object.entries(policy).forEach(([domain, servers]) => {
|
||||
if (Array.isArray(servers)) {
|
||||
// 处理数组格式的服务器
|
||||
const serversStr = servers.join(";");
|
||||
result.push(`${domain}=${serversStr}`);
|
||||
} else {
|
||||
// 处理单个服务器
|
||||
result.push(`${domain}=${servers}`);
|
||||
}
|
||||
});
|
||||
|
||||
return result.join(", ");
|
||||
};
|
||||
|
||||
// 解析nameserver-policy为对象
|
||||
const parseNameserverPolicy = (str: string): Record<string, any> => {
|
||||
const result: Record<string, any> = {};
|
||||
if (!str) return result;
|
||||
|
||||
str.split(",").forEach((item) => {
|
||||
const parts = item.trim().split("=");
|
||||
if (parts.length < 2) return;
|
||||
// 处理geosite:xxx,yyy格式
|
||||
const ruleRegex = /\s*([^=]+?)\s*=\s*([^,]+)(?:,|$)/g;
|
||||
let match;
|
||||
|
||||
const domain = parts[0].trim();
|
||||
const serversStr = parts.slice(1).join("=").trim();
|
||||
while ((match = ruleRegex.exec(str)) !== null) {
|
||||
const [, domainsPart, serversPart] = match;
|
||||
|
||||
// 检查是否包含多个分号分隔的服务器
|
||||
if (serversStr.includes(";")) {
|
||||
// 多个服务器,作为数组处理
|
||||
result[domain] = serversStr
|
||||
.split(";")
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean);
|
||||
// 处理域名部分
|
||||
let domains;
|
||||
if (domainsPart.startsWith("geosite:")) {
|
||||
domains = [domainsPart.trim()];
|
||||
} else {
|
||||
// 单个服务器
|
||||
result[domain] = serversStr;
|
||||
domains = [domainsPart.trim()];
|
||||
}
|
||||
});
|
||||
|
||||
// 处理服务器部分
|
||||
const servers = serversPart.split(";").map((s) => s.trim());
|
||||
|
||||
// 为每个域名组分配相同的服务器列表
|
||||
domains.forEach((domain) => {
|
||||
result[domain] = servers;
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
// 格式化nameserver-policy为字符串
|
||||
const formatNameserverPolicy = (policy: any): string => {
|
||||
if (!policy || typeof policy !== "object") return "";
|
||||
|
||||
// 直接将对象转换为字符串格式
|
||||
return Object.entries(policy)
|
||||
.map(([domain, servers]) => {
|
||||
const serversStr = Array.isArray(servers) ? servers.join(";") : servers;
|
||||
return `${domain}=${serversStr}`;
|
||||
})
|
||||
.join(", ");
|
||||
};
|
||||
|
||||
// 格式化hosts为字符串
|
||||
const formatHosts = (hosts: any): string => {
|
||||
if (!hosts || typeof hosts !== "object") return "";
|
||||
|
||||
Reference in New Issue
Block a user