Repository navigation
Conversation
Windows refuses to create a file or directory named CON, PRN, AUX, NUL,
COM1-COM9 or LPT1-LPT9, and an extension does not help: CON.txt is reserved
too. sanitize_path left those components untouched, so importing an album or
an artist with such a name failed with NotADirectoryError when beets tried to
create the directory.
Prefix an underscore instead. Following the CHAR_REPLACE rationale directly
above, this applies on every platform -- Samba shares hit the same limit.
Reproduced on Windows 10: sanitize_path("CON") returned "CON" and
os.makedirs failed with NotADirectoryError; same for "COM1".
Member
|
See our AI Policy. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Windows, a file or directory named
CON,PRN,AUX,NUL,COM1-COM9orLPT1-LPT9cannot be created at all. An extension does not help:CON.txtis reserved too.sanitize_path()leaves such components untouched, so importing an album or artist with one of those names fails when beets creates the destination directory.Reproduction (Windows 10, CPython 3.12)
Before this patch:
Change
sanitize_path()now prefixes such a component with an underscore (CON->_CON,CON.txt->_CON.txt). The check looks at the name before the first dot, because that is what Windows reserves.The rules apply on every platform, following the rationale already written above
CHAR_REPLACE: these names are legal on Unix, but Samba shares hit exactly the same wall, which is why the reserved characters are already stripped everywhere.Tests
Added to
TestSanitizePath:CON,con,CON.txt,NUL,aux.mp3,COM1,LPT9get the prefixnormal,console,con_,COM10,LPT0are left aloneResults:
pytest test/test_util.pypytest test/test_library.pyutil/__init__.pyfails exactly the 8 new casesA changelog entry is included under Unreleased -> Bug fixes.