From f4349f9a0b5f6e472fa8e27e9ded02bfaf0a9890 Mon Sep 17 00:00:00 2001 From: caohdgege <1170050364@qq.com> Date: Sun, 27 Dec 2020 12:24:29 +0800 Subject: [PATCH] bugfix: fix the value can not be push to nacos when special charset in config.txt (#3406) --- changes/1.5.0.md | 1 + changes/en-us/1.5.0.md | 1 + script/config-center/nacos/nacos-config.py | 7 ++++--- script/config-center/nacos/nacos-config.sh | 13 ++++++++++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/changes/1.5.0.md b/changes/1.5.0.md index 60495cf59..364bd8276 100644 --- a/changes/1.5.0.md +++ b/changes/1.5.0.md @@ -26,6 +26,7 @@ Seata 鏄竴娆惧紑婧愮殑鍒嗗竷寮忎簨鍔¤В鍐虫柟妗堬紝鎻愪緵楂樻€ц兘鍜岀畝鍗� - [[#3258](https://github.com/seata/seata/pull/3258)] 淇AsyncWorker娼滃湪鐨凮OM闂 - [[#3293](https://github.com/seata/seata/pull/3293)] 淇閰嶇疆缂撳瓨鑾峰彇鍊兼椂绫诲瀷涓嶅尮閰嶇殑bug - [[#3241](https://github.com/seata/seata/pull/3241)] 绂佹鍦ㄥSQL鐨勬儏鍐典笅浣跨敤 limit 鍜� order by 璇硶 + - [[#3406](https://github.com/seata/seata/pull/3406)] 淇褰揷onfig.txt涓寘鍚壒娈婂瓧绗︽椂锛岄敭鍊煎鏃犳硶琚帹涓妌acos diff --git a/changes/en-us/1.5.0.md b/changes/en-us/1.5.0.md index 45ff694fc..5fbe1f8ac 100644 --- a/changes/en-us/1.5.0.md +++ b/changes/en-us/1.5.0.md @@ -26,6 +26,7 @@ - [[#3258](https://github.com/seata/seata/pull/3258)] fix AsyncWorker potential OOM problem - [[#3293](https://github.com/seata/seata/pull/3293)] configuration cache get value cast exception - [[#3241](https://github.com/seata/seata/pull/3241)] forbidden use order by or limit in multi sql + - [[#3406](https://github.com/seata/seata/pull/3406)] fix the value can not be push to nacos when special charset in config.txt ### optimize锛� diff --git a/script/config-center/nacos/nacos-config.py b/script/config-center/nacos/nacos-config.py index 014caf183..7d41dd13b 100644 --- a/script/config-center/nacos/nacos-config.py +++ b/script/config-center/nacos/nacos-config.py @@ -3,6 +3,7 @@ import http.client import sys +import urllib.parse if len(sys.argv) <= 2: print ('python nacos-config.py nacosAddr') @@ -14,7 +15,7 @@ headers = { hasError = False for line in open('../config.txt'): - pair = line.split('=') + pair = line.rstrip("\n").split('=') if len(pair) < 2: continue print (line), @@ -22,9 +23,9 @@ for line in open('../config.txt'): conn = http.client.HTTPConnection(url_prefix) if len(sys.argv) == 3: namespace=sys.argv[2] - url_postfix = '/nacos/v1/cs/configs?dataId={0}&group=SEATA_GROUP&content={1}&tenant={2}'.format(str(pair[0]),str(line[line.index('=')+1:]).strip(),namespace) + url_postfix = '/nacos/v1/cs/configs?dataId={0}&group=SEATA_GROUP&content={1}&tenant={2}'.format(urllib.parse.quote(str(pair[0])),urllib.parse.quote(str(pair[1])).strip(),namespace) else: - url_postfix = '/nacos/v1/cs/configs?dataId={}&group=SEATA_GROUP&content={}'.format(str(pair[0]),str(line[line.index('=')+1:])).strip() + url_postfix = '/nacos/v1/cs/configs?dataId={}&group=SEATA_GROUP&content={}'.format(urllib.parse.quote(str(pair[0])),urllib.parse.quote(str(pair[1]))).strip() conn.request("POST", url_postfix, headers=headers) res = conn.getresponse() data = res.read() diff --git a/script/config-center/nacos/nacos-config.sh b/script/config-center/nacos/nacos-config.sh index 0f47b52e8..a2f7be91c 100644 --- a/script/config-center/nacos/nacos-config.sh +++ b/script/config-center/nacos/nacos-config.sh @@ -41,6 +41,17 @@ do esac done +urlencode() { + for ((i=0; i < ${#1}; i++)) + do + char="${1:$i:1}" + case $char in + [a-zA-Z0-9.~_-]) printf $char ;; + *) printf '%%%02X' "'$char" ;; + esac + done +} + if [[ -z ${host} ]]; then host=localhost fi @@ -69,7 +80,7 @@ echo "set group=$group" failCount=0 tempLog=$(mktemp -u) function addConfig() { - curl -X POST -H "${contentType}" "http://$nacosAddr/nacos/v1/cs/configs?dataId=$1&group=$group&content=$2&tenant=$tenant&username=$username&password=$password" >"${tempLog}" 2>/dev/null + curl -X POST -H "${contentType}" "http://$nacosAddr/nacos/v1/cs/configs?dataId=$(urlencode $1)&group=$group&content=$(urlencode $2)&tenant=$tenant&username=$username&password=$password" >"${tempLog}" 2>/dev/null if [[ -z $(cat "${tempLog}") ]]; then echo " Please check the cluster status. " exit 1 -- GitLab