Skip to content

Commit

Permalink
Merge pull request #170 from IDEMSInternational/iss158
Browse files Browse the repository at this point in the history
Enforce field keys starting with a letter
  • Loading branch information
fagiothree authored Mar 7, 2025
2 parents 62e1c46 + 7170723 commit b8913e2
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 b8913e2

Please sign in to comment.