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

strip the prum finisher input before assigning to key #1223

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions news/strip-prum_finisher.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* All inputs of `_id`s are now stripped before assigning to variables

**Security:**

* <news item>
2 changes: 1 addition & 1 deletion src/regolith/helpers/u_finishprumhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def construct_global_ctx(self):

def db_updater(self):
rc = self.rc
key = rc.projectum_id
key = rc.projectum_id.strip()
filterid = {"_id": key}
found_projectum = rc.client.find_one(rc.database, rc.coll, filterid)
if not found_projectum:
Expand Down
26 changes: 26 additions & 0 deletions src/regolith/runcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,32 @@
FORBIDDEN_NAMES = frozenset(["del", "global"])


def strip_rc(rc):
"""strip whitespace from all string-like rc members

Parameters
----------
rc : runcontrol object
The rc with unstripped strings

Return
------
rc : runcontrol object
The rc with all strings sstripped of whitespace
"""
stripped_rc = rc.__class__()
for attr in dir(rc):
if not attr.startswith("__"):
value = getattr(rc, attr)
if isinstance(value, str):
print("str", attr, value)
setattr(stripped_rc, attr, value.strip())
else:
print("non-str", attr, value)
setattr(stripped_rc, attr, value)
return stripped_rc


def warn_forbidden_name(forname, inname=None, rename=None):
"""Warns the user that a forbidden name has been found."""
msg = "found forbidden name {0!r}".format(forname)
Expand Down
9 changes: 8 additions & 1 deletion tests/test_runcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

from regolith.database import connect
from regolith.runcontrol import DEFAULT_RC, connect_db, filter_databases, load_rcfile
from regolith.runcontrol import DEFAULT_RC, connect_db, filter_databases, load_rcfile, strip_rc


def test_connect_db(make_db):
Expand All @@ -17,3 +17,10 @@ def test_connect_db(make_db):
chained_db, dbs = connect_db(rc)
assert chained_db == expected_chdb
assert dbs == expected_dbs


def test_strip_rc():
rc = copy.copy(DEFAULT_RC)
rc.new_thing = "new_thing "
rc = strip_rc(rc)
assert rc.new_thing == "new_thing"
Loading