Skip to content

Commit a7d9411

Browse files
committed
Ensure all values are wrapped in quotes if relevant with if-defined chk
1 parent 7dac3d7 commit a7d9411

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

wdlgen/task.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,22 @@ def get_string(self):
160160
options.append(f"default={val}")
161161
if array_sep:
162162
options.append(f'sep="{array_sep}"')
163-
if true or false:
163+
is_flag = true or false
164+
if is_flag:
164165
options.append(f'true="{true if true else ""}"')
165166
options.append(f'false="{false if false else ""}"')
166167

167168
stroptions = "".join(o + " " for o in options)
168169

169-
if self.optional and not default:
170+
if self.optional and not default and not is_flag:
170171
prewithquotes = f'"{bc}" + ' if bc.strip() else ""
171-
return f"~{{{stroptions}{prewithquotes}{name}}}"
172+
# Option 1: We apply quotes are value, Option 2: We quote whole "prefix + name" combo
173+
full_token = (
174+
f"{prewithquotes} '\"' + {name} + '\"'"
175+
if (self.separate and self.prefix and prewithquotes)
176+
else f"'\"' + {prewithquotes}{name} + '\"'"
177+
)
178+
return f'~{{{stroptions}if defined({name}) then ({full_token}) else ""}}'
172179
else:
173180
return bc + f"~{{{stroptions}{name}}}"
174181

0 commit comments

Comments
 (0)