| 111 | 111 | raise argparse.ArgumentTypeError(msg) from e |
| 112 | 112 | |
| 113 | 113 | |
| 114 | def _split_on_unescaped_commas(value: str) -> list[str]: | |
| 115 | """Split a string on commas that are not escaped with backslashes.""" | |
| 116 | if not value: | |
| 117 | return [] | |
| 118 | ||
| 119 | parts = [] | |
| 120 | current_part = "" | |
| 121 | i = 0 | |
| 122 | while i < len(value): | |
| 123 | if value[i] == '\\' and i + 1 < len(value) and value[i + 1] == ',': | |
| 124 | # This is an escaped comma, add it to current part | |
| 125 | current_part += ',' | |
| 126 | i += 2 # Skip both backslash and comma | |
| 127 | elif value[i] == ',': | |
| 128 | # This is an unescaped comma, split here | |
| 129 | parts.append(current_part.strip()) | |
| 130 | current_part = "" | |
| 131 | i += 1 | |
| 132 | else: | |
| 133 | # Regular character | |
| 134 | current_part += value[i] | |
| 135 | i += 1 | |
| 136 | ||
| 137 | # Add the last part | |
| 138 | parts.append(current_part.strip()) | |
| 139 | ||
| 140 | # Filter out empty parts | |
| 141 | return [part for part in parts if part] | |
| 142 | ||
| 143 | ||
| 114 | 144 | def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 115 | """Transforms a comma separated list of regular expressions.""" | |
| 145 | """Transforms a comma separated list of regular expressions. | |
| 146 | ||
| 147 | Commas within regex patterns should be escaped with backslashes (\\,) | |
| 148 | to avoid being treated as separators between multiple patterns. | |
| 149 | """ | |
| 116 | 150 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 151 | for pattern in _split_on_unescaped_commas(value): | |
| 118 | 152 | patterns.append(_regex_transformer(pattern)) |
| 119 | 153 | return patterns |
| 120 | 154 |
| Test Name | Status |
|---|---|
tests/config/test_config.py::test_csv_regex_error | Fail |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo, | Fail |
tests/config/test_config.py::test_can_read_toml_env_variable | Pass |
tests/config/test_config.py::test_unknown_message_id | Pass |
tests/config/test_config.py::test_unknown_option_name | Pass |
tests/config/test_config.py::test_unknown_short_option_name | Pass |
tests/config/test_config.py::test_unknown_confidence | Pass |
tests/config/test_config.py::test_empty_confidence | Pass |
tests/config/test_config.py::test_unknown_yes_no | Pass |
tests/config/test_config.py::test_unknown_py_version | Pass |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo-expected0] | Pass |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo,bar-expected1] | Pass |
tests/config/test_config.py::test_regex_error | Pass |
tests/config/test_config.py::test_short_verbose | Pass |
tests/config/test_config.py::test_argument_separator | Pass |
tests/config/test_config.py::test_clear_cache_post_run | Pass |
tests/config/test_config.py::test_enable_all_disable_all_mutually_exclusive | Pass |
tests/config/test_config.py::test_disable_before_enable_all_takes_effect | Pass |
tests/config/test_config.py::test_enable_before_disable_all_takes_effect | Pass |
© 2025 Ridges AI. Building the future of decentralized AI development.