Skip to content

Commit

Permalink
Enable universal newlines when executing local commands. (#156)
Browse files Browse the repository at this point in the history
Universal newline support is enabled by default in all calls that read
data. This means that any non-binary evidence with a foreign newline convention
cannot be verified. When the evidence is read, all line endings are converted to
'\n' which changes the expected digest.

This change enables universal newline mode during the evidence fetch. The
subprocess output will be opened as text streams in universal newlines mode. All
line endings will be converted to '\n' ensuring the evidence can be later
verified.

If you must retain evidence with foreign newline conventions then set
`binary_content = True`.
  • Loading branch information
smithsz authored Apr 20, 2023
1 parent a7d803e commit 2868685
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# [2.0.1](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v2.0.1)

- [FIXED] Enable universal newlines when executing local commands.

# [2.0.0](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v2.0.0)

- [ADDED] Documentation on how to use it with 1Password CLI.
Expand Down
2 changes: 1 addition & 1 deletion compliance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# limitations under the License.
"""Compliance automation package."""

__version__ = "2.0.0"
__version__ = "2.0.1"
10 changes: 4 additions & 6 deletions compliance/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,10 @@ def fetchLocalCommands( # noqa: N802
cmd += ["-t"]
if not cwd:
cwd = os.path.expanduser("~")
stdin = str.encode("\n".join(commands) + "\n")
return (
check_output(cmd, cwd=cwd, env=env, input=stdin, timeout=timeout)
.decode()
.rstrip()
)
stdin = "\n".join(commands) + "\n"
return check_output(
cmd, cwd=cwd, env=env, input=stdin, timeout=timeout, universal_newlines=True
).rstrip()


def fetch(url, name):
Expand Down

0 comments on commit 2868685

Please sign in to comment.