[whyour/qinglong][BUG] 多行环境变量添加问题

2024-01-17 730 views
5
版本:v2.12.1

在青龙面板里添加一些多行的环境变量时,会出现一些奇怪的问题,例如:

1. 空格丢失

想要添加如下CURL变量:

curl -k -X GET -H "Content-Type: application/json" -H "Host: example.com" -H "Connection: keep-alive" "https://example.com"

在env.sh文件中会变成如下所示,失去了空格:

export CURL='curl-k-XGET-H"Content-Type:application/json"-H"Host:example.com"-H"Connection:keep-alive""https://example.com"'
2. 引号转译问题

想要添加如下CURL变量:

curl 'https://example.com' \
  -H 'authority: example.com' \
  -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
  -H 'accept-language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7' \
  -H 'dnt: 1' \
  -H 'referer: https://example.com' \
  -H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "macOS"' \
  --compressed

在env.sh文件中会变成如下所示,单引号字符串错了(空格也丢失了):

export CURL='curl'https://example.com'\
-H'authority:example.com\
-H'accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'\
-H'accept-language:en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7'\
-H'dnt:1'\
-H'referer:https://example.com/'\
-H'sec-ch-ua:"NotA;Brand";v="99","Chromium";v="100","GoogleChrome";v="100"'\
-H'sec-ch-ua-mobile:?0'\
-H'sec-ch-ua-platform:"macOS"'\
--compressed'

回答

9

这个问题在v2.12.2中依旧没有解决。

添加一段环境变量,在env.sh中引号转译依然存在问题: export CURL="curl -k -X GET -H "Content-Type: application/json" -H "Connection: keep-alive" "https://example.com""

可以从Chrome中随机打开一个网址然后copy as curl作为环境变量添加进青龙即可复现。

2

这个不影响你脚本使用吧,里面的引号都转义了,你写个脚本获取这个环境变量试试

5

不行的,变量复杂时依然是不能获取完整。

这里以添加这条变量名为TEST的变量为例:

curl 'https://ip.sb/' \
  -H 'authority: ip.sb' \
  -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
  -H 'accept-language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7' \
  -H 'cache-control: max-age=0' \
  -H 'cookie: ipsb_session=d2c94496-0252-4048-22a2-042417305550; ipsb=AMDVB9yOXpGE8ntug3Hc5Cjql2FisoZ0; cf_clearance=F7T3GNsJJ._J3IWODb6VPyqNku2tQUsrluL5TO0rqVQ-1650524590-0-150' \
  -H 'dnt: 1' \
  -H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "macOS"' \
  -H 'sec-fetch-dest: document' \
  -H 'sec-fetch-mode: navigate' \
  -H 'sec-fetch-site: none' \
  -H 'sec-fetch-user: ?1' \
  -H 'upgrade-insecure-requests: 1' \
  -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36' \
  --compressed

运行如下脚本获取变量:

import os
print(os.environ.get('TEST'))

得到的结果是:

Screen Shot 2022-04-25 at 8 35 58 PM
4

而且还有个问题就是,反斜杠\被去掉了。

0

@xjasonlyu task执行的? 反斜杠本来就是个没有意义的符号,会自动转成一行执行

1

在task里执行依旧是不完整的,因为env.sh里的语义就错误了:

Screen Shot 2022-04-25 at 8 46 50 PM

反斜杠本来就是个没有意义的符号,会自动转成一行执行

反斜杠作为一个符号时是有意义的,例如我有个脚本需要从环境变量获取一个密钥,但是密钥里有个反斜杠,这时在青龙里就会报错。

例如添加\it's a special key\作为变量,运行就会出错:

Screen Shot 2022-04-25 at 8 55 06 PM