Skip to content

Commit

Permalink
fix: str_to_raw_id() may return empty id (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaoses-Ib committed Feb 12, 2024
1 parent b6ef34c commit 4a23832
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/comfy_script/astutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def str_to_raw_id(s: str) -> str:
s = f'_{s}'
s = re.sub(r'__+', '_', s)
s = s.rstrip('_')

if s == '':
s = '_'

if keyword.iskeyword(s):
s += '_'

Expand Down
8 changes: 8 additions & 0 deletions tests/test_astutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

import comfy_script.astutil as astutil

@pytest.mark.parametrize('s, id', [
(':<', '_'),
(':|', '_'),
(':/', '_'),
])
def test_str_to_raw_id(s, id):
assert astutil.str_to_raw_id(s) == id

@pytest.mark.parametrize('s, c', [
('', "''"),
("'", "'''\\''''"),
Expand Down

0 comments on commit 4a23832

Please sign in to comment.