提交 f68e95d4 编写于 作者: J jingxiaolu

parser: fix parse on ${A}

Fix a parse bug on ${A}

Fixes: #I1T68Q
Signed-off-by: Njingxiaolu <lujingxiao@huawei.com>
上级 e3e2dbe4
......@@ -23,7 +23,7 @@ import (
var (
// Split ${param} or $param.
// param should start with char
regParam = regexp.MustCompile(`[a-zA-Z][a-zA-Z0-9\-_]+`)
regParam = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9\-_]*`)
// regParamSpecial use to match ${variable:-word} and ${variable:+word}
regParamSpecial = regexp.MustCompile(`[a-zA-Z][a-zA-Z0-9\-\+_:]+`)
)
......
......@@ -73,6 +73,11 @@ func TestRegParam(t *testing.T) {
param: "1212",
matchFull: false,
},
{
name: "name 16",
param: "A",
matchFull: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
......@@ -356,6 +361,22 @@ func TestResolveParam(t *testing.T) {
want: `\$`,
wantErr: false,
},
{
name: "case 107",
args: args{
s: `${A}`,
strict: false,
resolveArg: func(s string) string {
if s == "A" {
return "found"
} else {
return "fail"
}
},
},
want: `found`,
wantErr: false,
},
{
// ${variable:-name}, match variable, return $variable
name: "case 201",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册