Skip to content

sanitize listname before formatting#2560

Merged
Silverarmor merged 4 commits into
spotDL:devfrom
tomdec:sanitize-m3u-before-formatting
May 13, 2026
Merged

sanitize listname before formatting#2560
Silverarmor merged 4 commits into
spotDL:devfrom
tomdec:sanitize-m3u-before-formatting

Conversation

@tomdec
Copy link
Copy Markdown
Contributor

@tomdec tomdec commented Nov 5, 2025

This is my first PR to an opensource project, so please let me know if I forgot something! :)

Title

Also sanitizes the injected list_name to prevent / characters in this name from creating unwanted directories.

Description

called the sanitize_string function on the inject list_name before replacing {list} or {list[idx]}.
Also added a rule to the sanitize_string function to remove double spaces (created by removing characters).

Related Issue

#2284

Motivation and Context

How Has This Been Tested?

I ran the tests on WSL in windows by running pytest in the cli, and using and extension in vs code.

Added a test that calls the gen_m3u_files with a list of songs that have "something / or other" as list_name.
Also tested it manually by downloading a spotify playlist with a / in the name.

Was going to evaluate the test results in GitHub to for other failing tests, because the tests in the master branch also have some failures locally.

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
    Pylint was happy, formatting with black is applied.
    For mypy, the first command ran successfully without errors, but then running just mypy ./spotdl did give some errors about missing library stubs, did the first command not create them all? Or is there another way to create them all?
  • My change requires a change to the documentation
    I don't think any changes altered expected functionality.
  • I have updated the documentation accordingly
  • I have read the CONTRIBUTING document
  • I have added tests to cover my changes
  • All new and existing tests passed
    I still have some failing tests when running all tests.
    Some I could fix with updating yt-dlp to 2025-10-22, but I have not committed this, am I allowed to update these dependencies?
    Most remaining failing tests had to do with CannotOverwriteExistingCassetteException and ContentDecodingError errors, which I'm not certain about how to fix.

@Silverarmor Silverarmor changed the base branch from master to dev March 8, 2026 07:53
@Silverarmor Silverarmor requested a review from Copilot May 4, 2026 06:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #2284 by preventing playlist/list names containing / from being interpreted as path separators when generating M3U filenames, avoiding unintended directory creation and FileNotFoundError on Windows.

Changes:

  • Sanitize {list} and {list[idx]} substitutions in gen_m3u_files() before str.format() to prevent path injection via list names.
  • Extend sanitize_string() to collapse double spaces introduced by removing disallowed characters.
  • Add a regression test ensuring gen_m3u_files() can handle a list_name containing /.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
spotdl/utils/m3u.py Sanitizes list names before formatting them into output M3U filenames.
spotdl/utils/formatter.py Adds whitespace cleanup after removing disallowed characters.
tests/utils/test_m3u.py Adds a test to verify M3U generation when list_name contains /.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/utils/test_m3u.py Outdated
Comment thread spotdl/utils/formatter.py Outdated
@Silverarmor Silverarmor merged commit d49082c into spotDL:dev May 13, 2026
2 of 8 checks passed
@Silverarmor
Copy link
Copy Markdown
Member

Apologies for the long delay. Thanks for your contribution @tomdec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants