Skip to content

Calling document.save() with a colon in the filename silently fails #1111

Open
@Pikamander2

Description

@Pikamander2

Calling document.save('Test:Test.docx') will successfully execute the code without throwing an OSError or similar exception, but the file will not be saved due to the unsanitized colon in the filename.

Instead, you'll get an empty file named Test with no file extension or content and the program will move onto the next instruction like nothing went wrong.

I've only tested this on Windows. The issue is presumably due to colons being disallowed in file names, but that should throw a hard error rather than silently failing.

One workaround is to encode the colon: document.save('Test:Test.docx'.replace(':', '%3A')) but this issue is really more about the silent failure rather than how to make it work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    opcpackagingPackaging and publishing python-docx to PyPI

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions