| 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 regular expressions that may contain commas by | |
| 118 | parsing them more carefully. It distinguishes between commas that | |
| 119 | separate multiple patterns and commas that are part of regex syntax. | |
| 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 comma-separated patterns while respecting regex syntax | |
| 130 | current_pattern = "" | |
| 131 | brace_count = 0 | |
| 132 | paren_count = 0 | |
| 133 | bracket_count = 0 | |
| 134 | in_quotes = False | |
| 135 | quote_char = None | |
| 136 | i = 0 | |
| 137 | ||
| 138 | while i < len(value): | |
| 139 | char = value[i] | |
| 140 | ||
| 141 | # Handle quoted patterns | |
| 142 | if char in "\"'" and not in_quotes: | |
| 143 | in_quotes = True | |
| 144 | quote_char = char | |
| 145 | current_pattern += char | |
| 146 | elif char == quote_char and in_quotes: | |
| 147 | in_quotes = False | |
| 148 | quote_char = None | |
| 149 | current_pattern += char | |
| 150 | elif in_quotes: | |
| 151 | current_pattern += char | |
| 152 | # Track nesting levels for regex constructs | |
| 153 | elif char == '{': | |
| 154 | brace_count += 1 | |
| 155 | current_pattern += char | |
| 156 | elif char == '}': | |
| 157 | brace_count = max(0, brace_count - 1) | |
| 158 | current_pattern += char | |
| 159 | elif char == '(': | |
| 160 | paren_count += 1 | |
| 161 | current_pattern += char | |
| 162 | elif char == ')': | |
| 163 | paren_count = max(0, paren_count - 1) | |
| 164 | current_pattern += char | |
| 165 | elif char == '[': | |
| 166 | bracket_count += 1 | |
| 167 | current_pattern += char | |
| 168 | elif char == ']': | |
| 169 | bracket_count = max(0, bracket_count - 1) | |
| 170 | current_pattern += char | |
| 171 | # Split on comma only if we're not inside any regex construct | |
| 172 | elif char == ',' and brace_count == 0 and paren_count == 0 and bracket_count == 0: | |
| 173 | pattern = current_pattern.strip() | |
| 174 | if pattern: # Only add non-empty patterns | |
| 175 | patterns.append(_regex_transformer(pattern)) | |
| 176 | current_pattern = "" | |
| 177 | else: | |
| 178 | current_pattern += char | |
| 179 | ||
| 180 | i += 1 | |
| 181 | ||
| 182 | # Add the last pattern | |
| 183 | pattern = current_pattern.strip() | |
| 184 | if pattern: | |
| 118 | 185 | patterns.append(_regex_transformer(pattern)) |
| 186 | ||
| 119 | 187 | return patterns |
| 120 | 188 | |
| 121 | 189 |
| 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.