| 114 | 114 | def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 115 | 115 | """Transforms a comma separated list of regular expressions.""" |
| 116 | 116 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 117 | for pattern in _regex_csv_split(value): | |
| 118 | 118 | patterns.append(_regex_transformer(pattern)) |
| 119 | 119 | return patterns |
| 120 | 120 | |
| 121 | 121 | |
| 122 | def _regex_csv_split(value: str) -> Sequence[str]: | |
| 123 | """Split a comma-separated list of regular expressions, respecting commas within regex patterns. | |
| 124 | ||
| 125 | This function handles commas that are part of regex syntax (like in quantifiers {1,3}) | |
| 126 | by only splitting on commas that are outside of balanced parentheses, brackets, and braces. | |
| 127 | """ | |
| 128 | if not value: | |
| 129 | return [] | |
| 130 | ||
| 131 | patterns: list[str] = [] | |
| 132 | current_pattern = "" | |
| 133 | paren_depth = 0 | |
| 134 | bracket_depth = 0 | |
| 135 | brace_depth = 0 | |
| 136 | ||
| 137 | i = 0 | |
| 138 | while i < len(value): | |
| 139 | char = value[i] | |
| 140 | ||
| 141 | # Handle escaped characters | |
| 142 | if char == "\\": | |
| 143 | current_pattern += char | |
| 144 | if i + 1 < len(value): | |
| 145 | current_pattern += value[i + 1] | |
| 146 | i += 1 | |
| 147 | # Track nesting levels | |
| 148 | elif char == "(": | |
| 149 | paren_depth += 1 | |
| 150 | current_pattern += char | |
| 151 | elif char == ")": | |
| 152 | paren_depth = max(0, paren_depth - 1) | |
| 153 | current_pattern += char | |
| 154 | elif char == "[": | |
| 155 | bracket_depth += 1 | |
| 156 | current_pattern += char | |
| 157 | elif char == "]": | |
| 158 | bracket_depth = max(0, bracket_depth - 1) | |
| 159 | current_pattern += char | |
| 160 | elif char == "{": | |
| 161 | brace_depth += 1 | |
| 162 | current_pattern += char | |
| 163 | elif char == "}": | |
| 164 | brace_depth = max(0, brace_depth - 1) | |
| 165 | current_pattern += char | |
| 166 | # Split on comma only if we're not inside any nested structure | |
| 167 | elif char == "," and paren_depth == 0 and bracket_depth == 0 and brace_depth == 0: | |
| 168 | pattern = current_pattern.strip() | |
| 169 | if pattern: # Only add non-empty patterns | |
| 170 | patterns.append(pattern) | |
| 171 | current_pattern = "" | |
| 172 | else: | |
| 173 | current_pattern += char | |
| 174 | ||
| 175 | i += 1 | |
| 176 | ||
| 177 | # Add the last pattern | |
| 178 | pattern = current_pattern.strip() | |
| 179 | if pattern: | |
| 180 | patterns.append(pattern) | |
| 181 | ||
| 182 | return patterns | |
| 183 | ||
| 184 | ||
| 122 | 185 | def _regexp_paths_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 123 | 186 | """Transforms a comma separated list of regular expressions paths.""" |
| 124 | 187 | patterns: list[Pattern[str]] = [] |
| 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.