| 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 within regex patterns by parsing the input | |
| 118 | more intelligently, only splitting on commas that are not inside | |
| 119 | parentheses, brackets, braces, or quotes. | |
| 120 | """ | |
| 121 | if not value: | |
| 122 | return [] | |
| 123 | ||
| 124 | # Parse CSV while respecting regex syntax | |
| 125 | patterns_str: list[str] = [] | |
| 126 | current_pattern = "" | |
| 127 | i = 0 | |
| 128 | paren_count = 0 | |
| 129 | bracket_count = 0 | |
| 130 | brace_count = 0 | |
| 131 | in_single_quote = False | |
| 132 | in_double_quote = False | |
| 133 | ||
| 134 | while i < len(value): | |
| 135 | char = value[i] | |
| 136 | ||
| 137 | # Handle escape sequences | |
| 138 | if char == "\\": | |
| 139 | if i + 1 < len(value): | |
| 140 | current_pattern += value[i:i+2] | |
| 141 | i += 2 | |
| 142 | continue | |
| 143 | ||
| 144 | # Handle quotes | |
| 145 | if char == "'" and not in_double_quote: | |
| 146 | in_single_quote = not in_single_quote | |
| 147 | current_pattern += char | |
| 148 | i += 1 | |
| 149 | continue | |
| 150 | elif char == '"': | |
| 151 | in_double_quote = not in_double_quote | |
| 152 | current_pattern += char | |
| 153 | i += 1 | |
| 154 | continue | |
| 155 | ||
| 156 | # Track nesting levels if not in quotes | |
| 157 | if not in_single_quote and not in_double_quote: | |
| 158 | if char == '(': | |
| 159 | paren_count += 1 | |
| 160 | elif char == ')': | |
| 161 | paren_count -= 1 | |
| 162 | elif char == '[': | |
| 163 | bracket_count += 1 | |
| 164 | elif char == ']': | |
| 165 | bracket_count -= 1 | |
| 166 | elif char == '{': | |
| 167 | brace_count += 1 | |
| 168 | elif char == '}': | |
| 169 | brace_count -= 1 | |
| 170 | ||
| 171 | # Handle comma separation - only split if not inside any brackets/quotes | |
| 172 | if char == "," and paren_count == 0 and bracket_count == 0 and brace_count == 0 and not in_single_quote and not in_double_quote: | |
| 173 | if current_pattern.strip(): | |
| 174 | patterns_str.append(current_pattern.strip()) | |
| 175 | current_pattern = "" | |
| 176 | i += 1 | |
| 177 | continue | |
| 178 | ||
| 179 | current_pattern += char | |
| 180 | i += 1 | |
| 181 | ||
| 182 | # Add the last pattern | |
| 183 | if current_pattern.strip(): | |
| 184 | patterns_str.append(current_pattern.strip()) | |
| 185 | ||
| 186 | # Compile all patterns | |
| 116 | 187 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 188 | for pattern in patterns_str: | |
| 118 | 189 | patterns.append(_regex_transformer(pattern)) |
| 119 | 190 | return patterns |
| 120 | 191 |
| 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.