helm 处理特殊符号 : 前面加 \\\

如下面,key :users 的value 带有双引号,就要特殊处理:

value.yml
game:
  users: "{:username \\\"账号100\\\" :password xxxxxxeeeeee}"

deployment.yml:
  env:
    - name: USERS
      value: "{{ .Values.game.users }}"

 

特殊符号如果没转换的错误:

 

Error: failed to parse ./values.yaml: error converting YAML to JSON: yaml: line 14: did not find expected node content

Error: UPGRADE FAILED: YAML parse error on test/templates/deployment.yaml: error converting YAML to JSON: yaml: line 24: did not find expected node content

 

其他:

一、百度查找 “json 特殊字符:

二、json引号问题

参考:http://www.cnblogs.com/hanyun/archive/2012/05/11/2495724.html

JSON中如果包含引号或双引号,会破坏JSON的格式。有两种方法可以解决。

在入库的时候可以使用addslashes()函数处理一下字符串,给引号前加上斜杠。被改的字符包括单引号 (')、双引号 (")、反斜线 backslash (\) 以及空字符NULL。

$text = addslashes($text);

JavaScript的话,可以这样:

function valueReplace(v){
    v=v.toString().replace(new RegExp('(["\"])', 'g'),"\\\"");
    return v;
}
var eValue = encodeURI($.trim(valueReplace(e.value)))

 

更多推荐