| 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 | Patterns containing commas can be quoted with single or double quotes. | |
| 118 | For example: "(foo{1,3})",bar.* will be parsed as two patterns: | |
| 119 | (foo{1,3}) and bar.* | |
| 120 | ||
| 121 | Commas can also be escaped with double backslashes: (foo{1\\,3}),bar.* | |
| 122 | """ | |
| 116 | 123 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 118 | patterns.append(_regex_transformer(pattern)) | |
| 124 | ||
| 125 | # Handle empty string case | |
| 126 | if not value.strip(): | |
| 127 | return patterns | |
| 128 | ||
| 129 | # Parse patterns handling quotes and escaped commas | |
| 130 | parts = [] | |
| 131 | current = "" | |
| 132 | in_quotes = False | |
| 133 | quote_char = None | |
| 134 | i = 0 | |
| 135 | ||
| 136 | while i < len(value): | |
| 137 | char = value[i] | |
| 138 | ||
| 139 | # Handle escape sequences | |
| 140 | if char == '\\' and i + 1 < len(value): | |
| 141 | next_char = value[i + 1] | |
| 142 | if next_char in ('"', "'", ','): | |
| 143 | # This is an escaped quote or comma, add both characters | |
| 144 | current += char + next_char | |
| 145 | i += 2 | |
| 146 | continue | |
| 147 | ||
| 148 | if char in ('"', "'") and not in_quotes: | |
| 149 | if not in_quotes: | |
| 150 | in_quotes = True | |
| 151 | quote_char = char | |
| 152 | elif char == quote_char: | |
| 153 | in_quotes = False | |
| 154 | quote_char = None | |
| 155 | current += char | |
| 156 | elif char == ',' and not in_quotes: | |
| 157 | parts.append(current) | |
| 158 | current = "" | |
| 159 | else: | |
| 160 | current += char | |
| 161 | i += 1 | |
| 162 | ||
| 163 | if current: | |
| 164 | parts.append(current) | |
| 165 | ||
| 166 | # Process each part | |
| 167 | for pattern in parts: | |
| 168 | pattern = pattern.strip() | |
| 169 | if not pattern: | |
| 170 | continue | |
| 171 | ||
| 172 | # Remove surrounding quotes if present | |
| 173 | if (pattern.startswith('"') and pattern.endswith('"')) or \ | |
| 174 | (pattern.startswith("'") and pattern.endswith("'")): | |
| 175 | pattern = pattern[1:-1] | |
| 176 | ||
| 177 | # Unescape escaped commas | |
| 178 | unescaped_pattern = pattern.replace('\\,', ',') | |
| 179 | patterns.append(_regex_transformer(unescaped_pattern)) | |
| 180 | ||
| 119 | 181 | return patterns |
| 120 | 182 | |
| 121 | 183 |
| 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.