Skip to content

Commit

Permalink
Fix regex in _parse_additional_config() (#1868)
Browse files Browse the repository at this point in the history
  • Loading branch information
zariiii9003 authored Oct 7, 2024
1 parent d4f3954 commit c5c18dc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion can/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def __call__(

def _parse_additional_config(unknown_args: Sequence[str]) -> TAdditionalCliArgs:
for arg in unknown_args:
if not re.match(r"^--[a-zA-Z\-]*?=\S*?$", arg):
if not re.match(r"^--[a-zA-Z][a-zA-Z0-9\-]*=\S*?$", arg):
raise ValueError(f"Parsing argument {arg} failed")

def _split_arg(_arg: str) -> Tuple[str, str]:
Expand Down
4 changes: 4 additions & 0 deletions test/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def test_parse_additional_config(self):
"--receive-own-messages=True",
"--false-boolean=False",
"--offset=1.5",
"--tseg1-abr=127",
]
parsed_args = can.logger._parse_additional_config(unknown_args)

Expand All @@ -170,6 +171,9 @@ def test_parse_additional_config(self):
assert "offset" in parsed_args
assert parsed_args["offset"] == 1.5

assert "tseg1_abr" in parsed_args
assert parsed_args["tseg1_abr"] == 127

with pytest.raises(ValueError):
can.logger._parse_additional_config(["--wrong-format"])

Expand Down

0 comments on commit c5c18dc

Please sign in to comment.