Skip to content

Commit

Permalink
Fix the record field name validator regex (#151)
Browse files Browse the repository at this point in the history
The original regex allowed a literal "[]" at the end of a name, which
breaks using the name as Python identifier.
  • Loading branch information
pyrco authored Nov 11, 2024
1 parent c17dc6b commit 941f2cb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flow/record/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
RECORDSTREAM_MAGIC = b"RECORDSTREAM\n"
RECORDSTREAM_MAGIC_DEPTH = 4 + 2 + len(RECORDSTREAM_MAGIC)

RE_VALID_FIELD_NAME = re.compile(r"^_?[a-zA-Z][a-zA-Z0-9_]*(?:\[\])?$")
RE_VALID_FIELD_NAME = re.compile(r"^_?[a-zA-Z][a-zA-Z0-9_]*$")
RE_VALID_RECORD_TYPE_NAME = re.compile("^[a-zA-Z][a-zA-Z0-9_]*(/[a-zA-Z][a-zA-Z0-9_]*)*$")

RECORD_CLASS_TEMPLATE = """
Expand Down
2 changes: 2 additions & 0 deletions tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ def test_mixed_case_name():
assert is_valid_field_name("Test")
assert is_valid_field_name("test")
assert is_valid_field_name("TEST")
assert not is_valid_field_name("test[]")
assert not is_valid_field_name("_test")

TestRecord = RecordDescriptor(
"Test/Record",
Expand Down

0 comments on commit 941f2cb

Please sign in to comment.