Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert argument to str in aiida.common.escaping.escape_for_bash #3873

Merged
merged 1 commit into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aiida/common/escaping.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def escape_for_bash(str_to_escape):
if str_to_escape is None:
return ''

str_to_escape = str(str_to_escape)

escaped_quotes = str_to_escape.replace("'", """'"'"'""")
return "'{}'".format(escaped_quotes)

Expand Down
18 changes: 18 additions & 0 deletions tests/common/test_escaping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
"""Tests for the :mod:`aiida.common.escaping`."""
from aiida.common.escaping import escape_for_bash


def test_escape_for_bash():
"""Tests various inputs for `aiida.common.escaping.escape_for_bash`."""
tests = (
[None, ''],
['string', "'string'"],
['string with space', "'string with space'"],
["string with a ' single quote", """'string with a '"'"' single quote'"""],
[1, "'1'"],
[2.0, "'2.0'"],
)

for string_input, string_escaped in tests:
assert escape_for_bash(string_input) == string_escaped