简体   繁体   中英

weird issue when sending a map with a value that has "," in it, as parameter in groovy

here is my situation:

func1(){
   def value1 = "gal,dan"
   def prop = ['names': value1]
   func2(prop)
}

func2(prop){
   def params_str = prop.collect { k, v -> "k=v" }.join(' ')
}

now i'm getting: dan has no value meaning it treats the ',' inside the first value as the ',' to go to the next key value pair

anyone got an idea how to fix it?

i tried encoding and decoding it but its pointless since when i decode it it still treats the ',' as go to the next key value pair

i tried sending it like ['names': "$value1"] and it failed too i tried adding "/'gal,dan/'" and it failed too

i expect names=gal,dan

You need to surround the value1 variable with quotes to indicate that it is a single string value.

func1() {
   def value1 = "gal,dan"
   def prop = ['names': "'$value1'"]
   func2(prop)
 }

func2(prop) {
   def params_str = prop.collect { k, v -> "k=$v" }.join(' ')
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM