| 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 may contain commas by using | |
| 118 | a more sophisticated parsing approach. | |
| 119 | ||
| 120 | The function first attempts CSV parsing. If all resulting patterns are | |
| 121 | valid regex patterns, it uses them. Otherwise, it treats the entire | |
| 122 | input as a single regex pattern. This preserves backward compatibility | |
| 123 | while fixing the issue with regex patterns containing commas. | |
| 124 | ||
| 125 | Commas can be escaped with a backslash (\\,) to be treated as literal | |
| 126 | commas within regex patterns. | |
| 127 | """ | |
| 116 | 128 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 118 | patterns.append(_regex_transformer(pattern)) | |
| 119 | return patterns | |
| 129 | ||
| 130 | if not value: | |
| 131 | return patterns | |
| 132 | ||
| 133 | # First, try CSV parsing with escaped comma support | |
| 134 | current_pattern = "" | |
| 135 | escape_next = False | |
| 136 | csv_patterns: list[str] = [] | |
| 137 | ||
| 138 | for char in value: | |
| 139 | if escape_next: | |
| 140 | # Add the escaped character literally | |
| 141 | current_pattern += char | |
| 142 | escape_next = False | |
| 143 | elif char == "\\": | |
| 144 | # Next character is escaped | |
| 145 | escape_next = True | |
| 146 | elif char == ",": | |
| 147 | # Comma separator - process the current pattern if not escaped | |
| 148 | if current_pattern.strip(): | |
| 149 | # Replace escaped commas with literal commas | |
| 150 | clean_pattern = current_pattern.replace("\\,", ",") | |
| 151 | csv_patterns.append(clean_pattern) | |
| 152 | current_pattern = "" | |
| 153 | else: | |
| 154 | current_pattern += char | |
| 155 | ||
| 156 | # Process the last pattern | |
| 157 | if current_pattern.strip(): | |
| 158 | clean_pattern = current_pattern.replace("\\,", ",") | |
| 159 | csv_patterns.append(clean_pattern) | |
| 160 | ||
| 161 | # Try to compile all CSV-parsed patterns | |
| 162 | csv_patterns_valid = True | |
| 163 | compiled_csv_patterns: list[Pattern[str]] = [] | |
| 164 | ||
| 165 | for pattern_str in csv_patterns: | |
| 166 | try: | |
| 167 | compiled_csv_patterns.append(_regex_transformer(pattern_str)) | |
| 168 | except argparse.ArgumentTypeError: | |
| 169 | csv_patterns_valid = False | |
| 170 | break | |
| 171 | ||
| 172 | # If all CSV patterns are valid, use them | |
| 173 | # Otherwise, treat the entire input as a single pattern | |
| 174 | if csv_patterns_valid and len(csv_patterns) > 1: | |
| 175 | return compiled_csv_patterns | |
| 176 | else: | |
| 177 | # Try to compile the entire input as a single pattern | |
| 178 | return [_regex_transformer(value)] | |
| 120 | 179 | |
| 121 | 180 | |
| 122 | 181 | def _regexp_paths_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| Test Name | Status |
|---|---|
tests/config/test_config.py::test_csv_regex_error | Fail |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo, | 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_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.