| 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 regex patterns that contain commas by parsing | |
| 118 | them intelligently, not splitting on commas that are within regex | |
| 119 | constructs like parentheses, brackets, or braces. | |
| 120 | """ | |
| 116 | 121 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 122 | ||
| 123 | # Handle the case where value is already a list/tuple | |
| 124 | if isinstance(value, (list, tuple)): | |
| 125 | for pattern in value: | |
| 126 | patterns.append(_regex_transformer(pattern)) | |
| 127 | return patterns | |
| 128 | ||
| 129 | # Parse the string intelligently to handle commas within regex patterns | |
| 130 | if not value.strip(): | |
| 131 | return patterns | |
| 132 | ||
| 133 | # Use a simple state machine to parse comma-separated regex patterns | |
| 134 | # while respecting parentheses, brackets, and braces | |
| 135 | current_pattern = "" | |
| 136 | paren_depth = 0 | |
| 137 | bracket_depth = 0 | |
| 138 | brace_depth = 0 | |
| 139 | in_char_class = False | |
| 140 | i = 0 | |
| 141 | ||
| 142 | while i < len(value): | |
| 143 | char = value[i] | |
| 144 | ||
| 145 | # Handle escape sequences first | |
| 146 | if char == '\\' and i + 1 < len(value): | |
| 147 | # Skip the next character, don't interpret it as a special char | |
| 148 | current_pattern += char + value[i + 1] | |
| 149 | i += 1 | |
| 150 | # Handle character classes [..] - commas inside should not split | |
| 151 | elif char == '[' and not in_char_class and paren_depth == 0 and bracket_depth == 0 and brace_depth == 0: | |
| 152 | in_char_class = True | |
| 153 | current_pattern += char | |
| 154 | elif char == ']' and in_char_class: | |
| 155 | in_char_class = False | |
| 156 | current_pattern += char | |
| 157 | elif in_char_class: | |
| 158 | current_pattern += char | |
| 159 | elif char == '(': | |
| 160 | paren_depth += 1 | |
| 161 | current_pattern += char | |
| 162 | elif char == ')': | |
| 163 | paren_depth -= 1 | |
| 164 | current_pattern += char | |
| 165 | elif char == '[': | |
| 166 | bracket_depth += 1 | |
| 167 | current_pattern += char | |
| 168 | elif char == ']': | |
| 169 | bracket_depth -= 1 | |
| 170 | current_pattern += char | |
| 171 | elif char == '{': | |
| 172 | brace_depth += 1 | |
| 173 | current_pattern += char | |
| 174 | elif char == '}': | |
| 175 | brace_depth -= 1 | |
| 176 | current_pattern += char | |
| 177 | elif char == ',' and paren_depth == 0 and bracket_depth == 0 and brace_depth == 0 and not in_char_class: | |
| 178 | # Found a separator comma, add the current pattern | |
| 179 | pattern = current_pattern.strip() | |
| 180 | if pattern: | |
| 181 | patterns.append(_regex_transformer(pattern)) | |
| 182 | current_pattern = "" | |
| 183 | else: | |
| 184 | current_pattern += char | |
| 185 | ||
| 186 | i += 1 | |
| 187 | ||
| 188 | # Add the last pattern | |
| 189 | pattern = current_pattern.strip() | |
| 190 | if pattern: | |
| 118 | 191 | patterns.append(_regex_transformer(pattern)) |
| 192 | ||
| 119 | 193 | return patterns |
| 120 | 194 | |
| 121 | 195 |
| 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.