amiliau
(Amiliau)
June 30, 2020, 10:13am
1
Variable substitution only replaces the first encountered instance of substring.
For example:
tags:
- ${DRONE_COMMIT_BRANCH/\//-}
am using a branch “feature/test/dashes” and am getting the following:
feature-test/dashes" is not a valid repository/tag
So it’s replaced the first instance of “/”, but not the second one. I would have expected it to replace all the instances of “/” in my branch name.
The reason is because a single /
replaces the first match, where as //
replaces all matches. If you want to replace all matches you can adjust the syntax slightly:
${stringZ//\//-}
We have a unit test that verifies this functionality:
input: "some text ${var01}$${var$${var01}$var01${var01}",
output: "some text abcdEFGH28ij${var${var01}$var01abcdEFGH28ij",
},
// some common escaping use cases
{
params: map[string]string{"stringZ": "foo/bar"},
input: `${stringZ/\//-}`,
output: "foo-bar",
},
{
params: map[string]string{"stringZ": "foo/bar/baz"},
input: `${stringZ//\//-}`,
output: "foo-bar-baz",
},
// substitute with a blank string
{
params: map[string]string{"stringZ": "foo.bar"},
input: `${stringZ/./}`,
output: "foobar",
},
}