| 112 | 112 | |
| 113 | 113 | |
| 114 | 114 | def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 115 | """Transforms a comma separated list of regular expressions.""" | |
| 115 | """Transforms a comma separated list of regular expressions. | |
| 116 | ||
| 117 | This function handles commas that are part of regular expressions (e.g., in | |
| 118 | character classes like [a,b] or quantifiers like {1,3}) by only splitting | |
| 119 | on commas that are at the top level of the parsing, not inside nested | |
| 120 | parentheses, brackets, or braces. | |
| 121 | """ | |
| 116 | 122 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 123 | ||
| 124 | # Handle empty string case | |
| 125 | if not value.strip(): | |
| 126 | return patterns | |
| 127 | ||
| 128 | # Parse the string, splitting only on commas that are not inside nested structures | |
| 129 | current_pattern = "" | |
| 130 | nesting_level = 0 | |
| 131 | i = 0 | |
| 132 | ||
| 133 | while i < len(value): | |
| 134 | char = value[i] | |
| 135 | ||
| 136 | # Track nesting level for parentheses, brackets, and braces | |
| 137 | if char in "([{" : | |
| 138 | nesting_level += 1 | |
| 139 | elif char in ")]}": | |
| 140 | nesting_level = max(0, nesting_level - 1) | |
| 141 | ||
| 142 | # Split on comma only if we're at the top level (not inside nested structures) | |
| 143 | if char == ',' and nesting_level == 0: | |
| 144 | # Add the current pattern if it's not empty | |
| 145 | pattern = current_pattern.strip() | |
| 146 | if pattern: | |
| 147 | patterns.append(_regex_transformer(pattern)) | |
| 148 | current_pattern = "" | |
| 149 | else: | |
| 150 | current_pattern += char | |
| 151 | ||
| 152 | i += 1 | |
| 153 | ||
| 154 | # Add the last pattern | |
| 155 | pattern = current_pattern.strip() | |
| 156 | if pattern: | |
| 118 | 157 | patterns.append(_regex_transformer(pattern)) |
| 158 | ||
| 119 | 159 | return patterns |
| 120 | 160 | |
| 121 | 161 |
| Test Name | Status |
|---|---|
tests/config/test_config.py::test_csv_regex_error | 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_csv_regex_comma_in_quantifier[foo, | 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.