Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions flashforge/tcp/tcp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@

import asyncio
import logging
import re
from typing import List, Optional

from .gcode.gcodes import GCodes

logger = logging.getLogger(__name__)

# Regex for invalid characters in filenames
INVALID_FILENAME_CHARS_PATTERN = re.compile(r'[^\w\s\-\.\(\)\+%,@\[\]{}:;!#$^&*=<>?\/]')


class FlashForgeTcpClient:
"""
Expand Down Expand Up @@ -416,8 +420,7 @@ def _parse_file_list_response(self, response: str) -> List[str]:
filename = full_path[6:] # Remove '/data/' prefix

# Trim at the first invalid character (if any)
import re
match = re.search(r'[^\w\s\-\.\(\)\+%,@\[\]{}:;!#$^&*=<>?\/]', filename)
match = INVALID_FILENAME_CHARS_PATTERN.search(filename)
if match:
filename = filename[:match.start()]

Expand Down