Skip to content

Commit

Permalink
Merge pull request #116 from UiPath/feature/avoid-escape-equal-sign
Browse files Browse the repository at this point in the history
Avoid escaping string values with equal sign in complex parameters
  • Loading branch information
thschmitt authored May 13, 2024
2 parents d2379a7 + fa835b5 commit 022c5d8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
14 changes: 13 additions & 1 deletion commandline/type_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (c typeConverter) convertToObject(value string, parameter parser.Parameter)
obj := map[string]interface{}{}
assigns := c.splitEscaped(value, ';')
for _, assign := range assigns {
keyValue := c.splitEscaped(assign, '=')
keyValue := c.splitEscapedMaxCount(assign, '=', 2)
if len(keyValue) < 2 {
keyValue = append(keyValue, "")
}
Expand Down Expand Up @@ -243,6 +243,10 @@ func (c typeConverter) convertValueToBooleanArray(value string, parameter parser
}

func (c typeConverter) splitEscaped(str string, separator byte) []string {
return c.splitEscapedMaxCount(str, separator, -1)
}

func (c typeConverter) splitEscapedMaxCount(str string, separator byte, maxCount int) []string {
result := []string{}
item := []byte{}
escaping := false
Expand All @@ -256,6 +260,14 @@ func (c typeConverter) splitEscaped(str string, separator byte) []string {
} else if char == separator && !escaping {
result = append(result, string(item))
item = []byte{}
if len(result) == maxCount-1 {
if i+1 < len(str) {
item = []byte(str[i+1:])
result = append(result, string(item))
}
break
}

} else {
escaping = false
item = append(item, char)
Expand Down
15 changes: 15 additions & 0 deletions commandline/type_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,21 @@ func TestNegativeIndexIsIgnored(t *testing.T) {
}
}

func TestConvertStringAvoidEscapeEqualSign(t *testing.T) {
converter := newTypeConverter()

parameter := newParameter("tag", parser.ParameterTypeObject,
[]parser.Parameter{
newParameter("name", parser.ParameterTypeString, []parser.Parameter{}),
})
result, _ := converter.Convert("name=hello=", parameter)

name := getValue(result, "name")
if name != "hello=" {
t.Errorf("Result should contain equal sign, but got: %v", name)
}
}

func getValue(result interface{}, key string) interface{} {
return result.(map[string]interface{})[key]
}
Expand Down

0 comments on commit 022c5d8

Please sign in to comment.