A filename crosses several parsers
The same name may pass through an HTTP header, browser download dialog, archive and local filesystem. Quoting rules, Unicode handling and reserved characters differ. Use a conservative naming policy and preserve richer display titles separately in the application.
What to do next
- 01
Choose a stable naming pattern
Use a short safe project label, immutable attempt or asset identifier and an extension based on validated content type. Avoid secrets, email addresses and full creative prompts, which may travel into shared folders or screenshots.
- 02
Serialize headers correctly
Use a reviewed Content-Disposition implementation for attachment naming, including non-ASCII support if required. Strip control characters and path components, and never concatenate a raw user title into an HTTP header or server path.
- 03
Test hostile and awkward names
Try line breaks, quotes, slashes, emoji, very long titles and reserved-looking names in local tests. Verify the downloaded bytes remain correct, the header is valid and archive extraction cannot create unintended paths.
A concrete example
Illustrative example: a project titled Spring / Summer: draft becomes a safe attachment such as spring-summer-a17.png. The richer project title remains visible in the app, while the filesystem name avoids path interpretation.
Before you call it ready
- Extensions match validated media types.
- Control characters never enter headers.
- Server paths use generated identifiers.
A locally executed, reproducible check
Windows and POSIX path rules disagree about backslashes in a proposed filename.
We executed this exact synthetic fixture on November 16, 2026 with Python 3.12.10 and SQLite 3.49.1. It ran locally with no network requests, account data or model generation. The recorded output below is an observation from that environment, not a platform benchmark. Copy the code into a separate Python file to repeat it in a suitable local environment; compare the mechanism and check your runtime version.
from pathlib import PurePosixPath,PureWindowsPath
candidate=r'..\private\result.png'
print('POSIX name:',PurePosixPath(candidate).name)
print('Windows name:',PureWindowsPath(candidate).name)
print('POSIX parts:',PurePosixPath(candidate).parts)
print('Windows parts:',PureWindowsPath(candidate).parts)
Recorded output and interpretation
This is a parsing contrast, not a complete safe-filename implementation. Use a generated basename and separately control the filesystem destination and HTTP header encoding. Removing traversal syntax alone does not address reserved names, controls, collisions or misleading extensions.
A matching local output establishes only the illustrated library or database behavior under these inputs. It does not certify a production integration. Preserve the approved action, authorization boundaries and current AISwapLab request contract when applying the idea.
POSIX name: ..\private\result.png
Windows name: result.png
POSIX parts: ('..\\private\\result.png',)
Windows parts: ('..', 'private', 'result.png')
When to stop or choose another method
Stop using raw prompt text or an unvalidated response filename as an attachment header or filesystem destination.
