| 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 | Handles regex patterns containing commas by parsing them more carefully. | |
| 118 | Commas inside regex constructs like {n,m}, character classes, etc. | |
| 119 | are preserved, while commas outside regex constructs are treated as separators. | |
| 120 | """ | |
| 121 | if not value.strip(): | |
| 122 | return [] | |
| 123 | ||
| 116 | 124 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 125 | current_pattern = "" | |
| 126 | brace_depth = 0 | |
| 127 | bracket_depth = 0 | |
| 128 | paren_depth = 0 | |
| 129 | in_quotes = False | |
| 130 | quote_char = None | |
| 131 | i = 0 | |
| 132 | ||
| 133 | while i < len(value): | |
| 134 | char = value[i] | |
| 135 | ||
| 136 | # Handle quoted strings | |
| 137 | if char in "\"'" and not in_quotes: | |
| 138 | in_quotes = True | |
| 139 | quote_char = char | |
| 140 | current_pattern += char | |
| 141 | i += 1 | |
| 142 | continue | |
| 143 | elif in_quotes and char == quote_char: | |
| 144 | # Check if the quote is escaped | |
| 145 | if i > 0 and value[i-1] != '\\': | |
| 146 | in_quotes = False | |
| 147 | quote_char = None | |
| 148 | current_pattern += char | |
| 149 | i += 1 | |
| 150 | continue | |
| 151 | elif in_quotes: | |
| 152 | current_pattern += char | |
| 153 | i += 1 | |
| 154 | continue | |
| 155 | ||
| 156 | # Track nesting levels for regex constructs | |
| 157 | if char == '{': | |
| 158 | brace_depth += 1 | |
| 159 | elif char == '}': | |
| 160 | brace_depth = max(0, brace_depth - 1) | |
| 161 | elif char == '[': | |
| 162 | bracket_depth += 1 | |
| 163 | elif char == ']': | |
| 164 | bracket_depth = max(0, bracket_depth - 1) | |
| 165 | elif char == '(': | |
| 166 | paren_depth += 1 | |
| 167 | elif char == ')': | |
| 168 | paren_depth = max(0, paren_depth - 1) | |
| 169 | ||
| 170 | # If we find a comma outside any nested constructs, treat it as a separator | |
| 171 | if char == ',' and brace_depth == 0 and bracket_depth == 0 and paren_depth == 0: | |
| 172 | pattern = current_pattern.strip() | |
| 173 | if pattern: | |
| 174 | patterns.append(_regex_transformer(pattern)) | |
| 175 | current_pattern = "" | |
| 176 | else: | |
| 177 | current_pattern += char | |
| 178 | ||
| 179 | i += 1 | |
| 180 | ||
| 181 | # Add the last pattern | |
| 182 | pattern = current_pattern.strip() | |
| 183 | if pattern: | |
| 118 | 184 | patterns.append(_regex_transformer(pattern)) |
| 185 | ||
| 119 | 186 | return patterns |
| 120 | 187 | |
| 121 | 188 |
| 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.