subconverter icon indicating copy to clipboard operation
subconverter copied to clipboard

[BUG]有关filter_script的node的parse的问题

Open jacobin opened this issue 7 months ago • 2 comments

verify

  • [X] 我已经仔细阅读项目文档,确认现有功能无法解决我的需求
  • [X] 我已经检索过现有issue,确认与现有issue的内容并不重复
  • [X] 我已经尝试自行解决,确认自己没有能力解决

功能描述

在subconverter的doc中,有话如下

#仅保留加密方式为chacha20的节点
filter_script=function filter(node){\n    if(node.EncryptMethod.includes('chacha20'))\n return true;\n return false;\n }
# 或者使用本地文件
filter_script="path:/path/to/script.js"

而在https://github.com/tindy2013/subconverter/blob/master/base/pref.example.ini 中,却是

;Enable script support for filtering nodes
enable_filter=false
;Script used for filtering nodes. Supports inline script and script path. A "filter" function with 1 argument which is a node should be defined in the script.
;Example: Inline script: Set value to content of script. Replace all line break with "\n".
;         Script path: set value to "path:/path/to/script.js".
;filter_script=function filter(node) {\n    const info = JSON.parse(node.ProxyInfo);\n    if(info.EncryptMethod.includes('chacha20'))\n        return true;\n    return false;\n}

两处的区别在于:后者有“const info = JSON.parse(node.ProxyInfo)”,亦即先从node解析到info,然后从info展开代码;而前者直接从node展开代码。

我认为它两不可能都是对的。请问,哪个是正确的?

可能的解决方案

N/A

jacobin avatar Dec 29 '23 17:12 jacobin

两者都是对的,不是bug,按需使用。

lonelam avatar Jan 21 '24 08:01 lonelam

两者都是对的,不是bug,按需使用。

👎 不可能的,除非作者吃饱了撑的

jacobin avatar Jan 24 '24 11:01 jacobin