Skip to content

Commit 00476a7

Browse files
Improve regex pattern handling
Co-authored-by: qodo-merge-pro[bot] <151058649+qodo-merge-pro[bot]@users.noreply.github.com>
1 parent 115bd12 commit 00476a7

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

Video/video_nodeQuery.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,19 @@ def normalize_filename(filename: str, trim_pattern: str) -> str:
9292

9393
# Convert trim pattern to regex
9494
# Handle character classes like [:alnum:]
95-
if "[:alnum:]" in trim_pattern:
96-
# Create regex pattern for alphanumeric characters plus other allowed chars
97-
allowed_chars = trim_pattern.replace("[:alnum:]", "a-zA-Z0-9")
98-
pattern = f"[^{allowed_chars}]"
99-
else:
100-
# Direct character set
101-
pattern = f"[^{re.escape(trim_pattern)}]"
95+
posix_classes = {
96+
"[:alnum:]": "a-zA-Z0-9",
97+
"[:alpha:]": "a-zA-Z",
98+
"[:digit:]": "0-9",
99+
"[:space:]": " \t\n\r\f\v"
100+
}
101+
102+
allowed_chars = trim_pattern
103+
for posix_class, replacement in posix_classes.items():
104+
if posix_class in allowed_chars:
105+
allowed_chars = allowed_chars.replace(posix_class, replacement)
106+
107+
pattern = f"[^{re.escape(allowed_chars)}]"
102108

103109
# Remove disallowed characters
104110
normalized = re.sub(pattern, "", normalized)

0 commit comments

Comments
 (0)