fix: outputs espace (#404)
* fix: outputs espace * refactor: move unescape to func * refactor: fix ci lint * refactor: unescape function
This commit is contained in:
parent
1e69525fb4
commit
92067eb1a5
2 changed files with 47 additions and 1 deletions
|
@ -38,7 +38,8 @@ func (rc *RunContext) commandHandler(ctx context.Context) common.LineHandler {
|
||||||
if resumeCommand != "" && command != resumeCommand {
|
if resumeCommand != "" && command != resumeCommand {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
arg = unescapeCommandData(arg)
|
||||||
|
kvPairs = unescapeKvPairs(kvPairs)
|
||||||
switch command {
|
switch command {
|
||||||
case "set-env":
|
case "set-env":
|
||||||
rc.setEnv(ctx, kvPairs, arg)
|
rc.setEnv(ctx, kvPairs, arg)
|
||||||
|
@ -95,3 +96,33 @@ func parseKeyValuePairs(kvPairs string, separator string) map[string]string {
|
||||||
}
|
}
|
||||||
return rtn
|
return rtn
|
||||||
}
|
}
|
||||||
|
func unescapeCommandData(arg string) string {
|
||||||
|
escapeMap := map[string]string{
|
||||||
|
"%25": "%",
|
||||||
|
"%0D": "\r",
|
||||||
|
"%0A": "\n",
|
||||||
|
}
|
||||||
|
for k, v := range escapeMap {
|
||||||
|
arg = strings.Replace(arg, k, v, -1)
|
||||||
|
}
|
||||||
|
return arg
|
||||||
|
}
|
||||||
|
func unescapeCommandProperty(arg string) string {
|
||||||
|
escapeMap := map[string]string{
|
||||||
|
"%25": "%",
|
||||||
|
"%0D": "\r",
|
||||||
|
"%0A": "\n",
|
||||||
|
"%3A": ":",
|
||||||
|
"%2C": ",",
|
||||||
|
}
|
||||||
|
for k, v := range escapeMap {
|
||||||
|
arg = strings.Replace(arg, k, v, -1)
|
||||||
|
}
|
||||||
|
return arg
|
||||||
|
}
|
||||||
|
func unescapeKvPairs(kvPairs map[string]string) map[string]string {
|
||||||
|
for k, v := range kvPairs {
|
||||||
|
kvPairs[k] = unescapeCommandProperty(v)
|
||||||
|
}
|
||||||
|
return kvPairs
|
||||||
|
}
|
||||||
|
|
|
@ -30,6 +30,21 @@ func TestSetOutput(t *testing.T) {
|
||||||
}
|
}
|
||||||
handler("::set-output name=x::valz\n")
|
handler("::set-output name=x::valz\n")
|
||||||
assert.Equal("valz", rc.StepResults["my-step"].Outputs["x"])
|
assert.Equal("valz", rc.StepResults["my-step"].Outputs["x"])
|
||||||
|
|
||||||
|
handler("::set-output name=x::percent2%25\n")
|
||||||
|
assert.Equal("percent2%", rc.StepResults["my-step"].Outputs["x"])
|
||||||
|
|
||||||
|
handler("::set-output name=x::percent2%25%0Atest\n")
|
||||||
|
assert.Equal("percent2%\ntest", rc.StepResults["my-step"].Outputs["x"])
|
||||||
|
|
||||||
|
handler("::set-output name=x::percent2%25%0Atest another3%25test\n")
|
||||||
|
assert.Equal("percent2%\ntest another3%test", rc.StepResults["my-step"].Outputs["x"])
|
||||||
|
|
||||||
|
handler("::set-output name=x%3A::percent2%25%0Atest\n")
|
||||||
|
assert.Equal("percent2%\ntest", rc.StepResults["my-step"].Outputs["x:"])
|
||||||
|
|
||||||
|
handler("::set-output name=x%3A%2C%0A%25%0D%3A::percent2%25%0Atest\n")
|
||||||
|
assert.Equal("percent2%\ntest", rc.StepResults["my-step"].Outputs["x:,\n%\r:"])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddpath(t *testing.T) {
|
func TestAddpath(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue