mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-07 20:54:14 +08:00
🤞 Sync 2026-09-30 09:28:31
This commit is contained in:
1 parent
0108cfa10a
commit
3d9edb1c37
78 files changed
+4594
-1815
No files matched your search
@@ -222,5 +222,81 @@ if fnodes and #fnodes >= 2 then
|
||||
end
|
||||
|
||||
-- ---------- 结果 ----------
|
||||
-- H6:未知 Clash 类型必须丢弃。透传出去会在输出端变成 sing-box 的 type: "snell"、
|
||||
-- Xray 的 protocol: "snell" 这类非法取值,客户端会拒绝加载整份配置;
|
||||
-- 兜底成 vmess 则是凭空造出一个字段全错的假节点,比丢弃更糟。
|
||||
local unknown = parser.parse([[
|
||||
proxies:
|
||||
- name: SN
|
||||
type: snell
|
||||
server: 1.1.1.1
|
||||
port: 443
|
||||
psk: secret
|
||||
- name: OK
|
||||
type: vmess
|
||||
server: 2.2.2.2
|
||||
port: 443
|
||||
uuid: u
|
||||
]])
|
||||
check("unknown clash type dropped", #unknown == 1)
|
||||
check("known node survives", unknown[1] ~= nil and unknown[1].proto == "vmess")
|
||||
check("unknown proto not leaked", unknown[1] ~= nil and unknown[1].proto ~= "snell")
|
||||
|
||||
-- 缺失 type 同样丢弃(不再兜底成 vmess)
|
||||
check("missing type dropped", #parser.parse([[
|
||||
proxies:
|
||||
- name: X
|
||||
server: 1.1.1.1
|
||||
port: 443
|
||||
]]) == 0)
|
||||
|
||||
-- H4a:YAML 流式风格(键未加引号)是合法 YAML 但不是合法 JSON,
|
||||
-- 原先 json_decode 失败后整项被静默丢弃
|
||||
local flow = parser.parse([[
|
||||
proxies:
|
||||
- {name: F, type: vmess, server: 1.1.1.1, port: 443, uuid: u}
|
||||
]])
|
||||
check("flow style node count", #flow == 1)
|
||||
check("flow style proto", flow[1] ~= nil and flow[1].proto == "vmess")
|
||||
check("flow style server", flow[1] ~= nil and flow[1].server == "1.1.1.1")
|
||||
check("flow style port is number", flow[1] ~= nil and flow[1].port == 443)
|
||||
|
||||
-- 流式风格的数组值仍要拆成 table
|
||||
local flow_arr = parser.parse([[
|
||||
proxies:
|
||||
- {name: FA, type: vmess, server: 1.1.1.1, port: 443, uuid: u, alpn: [h2, http/1.1]}
|
||||
]])
|
||||
check("flow style array value", flow_arr[1] ~= nil and type(flow_arr[1].alpn) == "table")
|
||||
|
||||
-- 键带引号的流式写法仍走 JSON 分支
|
||||
check("json flow style still works", #parser.parse([[
|
||||
proxies:
|
||||
- {"name":"J","type":"vmess","server":"1.1.1.1","port":443,"uuid":"u"}
|
||||
]]) == 1)
|
||||
|
||||
-- H4b:行尾注释不得被当成值(`proxies: # 说明` 曾让 proxies 变成字符串)
|
||||
local commented = parser.parse([[
|
||||
proxies: # 我的节点
|
||||
- name: C
|
||||
type: vmess
|
||||
server: 1.1.1.1
|
||||
port: 443
|
||||
uuid: u
|
||||
]])
|
||||
check("proxies with trailing comment", #commented == 1)
|
||||
check("comment not used as value", commented[1] ~= nil and commented[1].server == "1.1.1.1")
|
||||
|
||||
-- 列表项的行尾注释同样要去掉
|
||||
check("list item trailing comment", #parser.parse([[
|
||||
proxies:
|
||||
- {name: T, type: vmess, server: 1.1.1.1, port: 443, uuid: u} # 行尾注释
|
||||
]]) == 1)
|
||||
|
||||
-- # 前无空白、或位于引号内时都不是注释,必须原样保留
|
||||
local hash_plain = parser.parse("proxies:\n - name: A\n type: ss\n server: 1.1.1.1\n port: 443\n cipher: aes-128-gcm\n password: p#ss\n")
|
||||
check("hash without space kept", hash_plain[1] ~= nil and hash_plain[1].password == "p#ss")
|
||||
local hash_quoted = parser.parse('proxies:\n - name: A\n type: ss\n server: 1.1.1.1\n port: 443\n cipher: aes-128-gcm\n password: "a # b"\n')
|
||||
check("hash inside quotes kept", hash_quoted[1] ~= nil and hash_quoted[1].password == "a # b")
|
||||
|
||||
print(string.format("\n%d passed, %d failed", passed, failed))
|
||||
os.exit(failed == 0 and 0 or 1)
|
||||
Reference in new issue
Block a user