Skip to content

Commit 0a03625

Browse files
committed
Sanitise user input
We want to be as flexible as possible so don't want to be too limiting on how the user can interact with the function.
1 parent 1636eda commit 0a03625

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/nuclearmasses/mass_table.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,14 @@ def add_user_data(
3939
# One via code: DataSource to differentiate from the original table data
4040
required_columns = {"A", "Z", "DataSource"}
4141

42-
# Convert a string into a type read_json can read
42+
# Is the string a json string or filename
4343
if isinstance(data, str):
44-
data = io.StringIO(data)
44+
path = pathlib.Path(data)
45+
46+
if path.is_file():
47+
data = path
48+
else:
49+
data = io.StringIO(data)
4550

4651
# Read the file, should be valid json so nice and simple
4752
user_df: pd.DataFrame = pd.read_json(data, dtype={"A": int, "Z": int})

0 commit comments

Comments
 (0)