Skip to content

Commit

Permalink
Enforce variable names start with a letter
Browse files Browse the repository at this point in the history
  • Loading branch information
geoo89 committed Mar 7, 2025
1 parent 62e1c46 commit 7170723
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/rpft/rapidpro/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def generate_field_key(field_name):
{"length": len(key), "limit": FIELD_KEY_MAX_LENGTH, "key": key},
)

if not re.search("[A-Za-z]", key):
if not re.match(r"^[a-z][a-z0-9_]*$", key):
raise RapidProActionError(
"Contact field key without letter characters detected",
"Contact field key needs to start with a letter",
{"key": key, "name": field_name},
)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ def test_fail_if_max_key_length_exceeded(self):
with self.assertRaises(RapidProActionError):
generate_field_key("z" * 37)

def test_fail_if_key_does_not_contain_letters(self):
def test_fail_if_key_does_not_start_with_letter(self):
with self.assertRaises(RapidProActionError):
generate_field_key("123")
generate_field_key("1zx")

0 comments on commit 7170723

Please sign in to comment.