Skip to content

Commit 01913b0

Browse files
committed
Fix #823 (file contents interpreted as bytes)
This adds `.decode("utf-8")` to the end of instances where a file is read and makes sure that objects are interpreted as bytes when they are evaluated as expressions.
1 parent e4a5268 commit 01913b0

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

cwltool/builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def bind_input(self,
282282
self.files.append(datum)
283283
if (binding and binding.get("loadContents")) or schema.get("loadContents"):
284284
with self.fs_access.open(datum["location"], "rb") as f:
285-
datum["contents"] = f.read(CONTENT_LIMIT)
285+
datum["contents"] = f.read(CONTENT_LIMIT).decode("utf-8")
286286

287287
if "secondaryFiles" in schema:
288288
if "secondaryFiles" not in datum:

cwltool/command_line_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ def collect_output(self,
685685
if binding.get("loadContents") or compute_checksum:
686686
contents = f.read(CONTENT_LIMIT)
687687
if binding.get("loadContents"):
688-
files["contents"] = contents
688+
files["contents"] = contents.decode("utf-8")
689689
if compute_checksum:
690690
checksum = hashlib.sha1()
691691
while contents != b"":

cwltool/expression.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ def jshead(engine_config, rootvars):
1919

2020
# make sure all the byte strings are converted
2121
# to str in `rootvars` dict.
22-
# TODO: need to make sure the `rootvars dict`
23-
# contains no bytes type in the first place.
24-
if six.PY3:
25-
rootvars = bytes2str_in_dicts(rootvars) # type: ignore
2622

2723
return u"\n".join(
2824
engine_config + [u"var {} = {};".format(k, json_dumps(v, indent=4))
@@ -271,6 +267,11 @@ def do_eval(ex, # type: Union[Text, Dict]
271267
u"self": context,
272268
u"runtime": runtime}
273269

270+
# TODO: need to make sure the `rootvars dict`
271+
# contains no bytes type in the first place.
272+
if six.PY3:
273+
rootvars = bytes2str_in_dicts(rootvars) # type: ignore
274+
274275
if needs_parsing(ex):
275276
assert isinstance(ex, string_types)
276277
fullJS = False

cwltool/workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def postScatterEval(io):
335335
for k, v in io.items():
336336
if k in loadContents and v.get("contents") is None:
337337
with fs_access.open(v["location"], "rb") as f:
338-
v["contents"] = f.read(CONTENT_LIMIT)
338+
v["contents"] = f.read(CONTENT_LIMIT).decode("utf-8")
339339

340340
def valueFromFunc(k, v): # type: (Any, Any) -> Any
341341
if k in valueFrom:

0 commit comments

Comments
 (0)