Skip to content

Commit d77741b

Browse files
authored
Fix: include patterns (#76)
1 parent 4e5c952 commit d77741b

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/gitingest/parse_query.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import re
23
import string
34
import uuid
45
from typing import Any
@@ -77,17 +78,45 @@ def _normalize_pattern(pattern: str) -> str:
7778

7879

7980
def _parse_patterns(pattern: list[str] | str) -> list[str]:
81+
"""
82+
Parse and validate file/directory patterns for inclusion or exclusion.
83+
84+
Takes either a single pattern string or list of pattern strings and processes them into a normalized list.
85+
Patterns are split on commas and spaces, validated for allowed characters, and normalized.
86+
87+
Parameters
88+
----------
89+
pattern : list[str] | str
90+
Pattern(s) to parse - either a single string or list of strings
91+
92+
Returns
93+
-------
94+
list[str]
95+
List of normalized pattern strings
96+
97+
Raises
98+
------
99+
ValueError
100+
If any pattern contains invalid characters. Only alphanumeric characters,
101+
dash (-), underscore (_), dot (.), forward slash (/), plus (+), and
102+
asterisk (*) are allowed.
103+
"""
80104
patterns = pattern if isinstance(pattern, list) else [pattern]
81-
patterns = [p.strip() for p in patterns]
82105

106+
parsed_patterns = []
83107
for p in patterns:
108+
parsed_patterns.extend(re.split(",| ", p))
109+
110+
parsed_patterns = [p for p in parsed_patterns if p != ""]
111+
112+
for p in parsed_patterns:
84113
if not all(c.isalnum() or c in "-_./+*" for c in p):
85114
raise ValueError(
86115
f"Pattern '{p}' contains invalid characters. Only alphanumeric characters, dash (-), "
87116
"underscore (_), dot (.), forward slash (/), plus (+), and asterisk (*) are allowed."
88117
)
89118

90-
return [_normalize_pattern(p) for p in patterns]
119+
return [_normalize_pattern(p) for p in parsed_patterns]
91120

92121

93122
def _override_ignore_patterns(ignore_patterns: list[str], include_patterns: list[str]) -> list[str]:

0 commit comments

Comments
 (0)