Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added path string validation #574

Merged
merged 2 commits into from
Jan 19, 2024
Merged

Added path string validation #574

merged 2 commits into from
Jan 19, 2024

Conversation

AlexKalopsia
Copy link
Contributor

@AlexKalopsia AlexKalopsia commented Jan 17, 2024

I ran into a couple of situations where streamrip would fail to process the data if the album or the artist included special characters (even one case where the record name had a random trailing empty space).

The format I use is folder_format = "{albumartist}/{year} - {title}", hence an album like 2024 - Cool Name (note trailing space) or 2024 - Hot / Cold (special char) will fail the path creation, since it will try and create C:/2024 - Cool Name /__artwork (not valid, at least on Windows), or could try and split the path like C:/2024 - Hot / Cold/__artwork, and also fail in the process.

The PR just adds a simple string validation to prevent any of those invalid characters, as well as trailing spaces.

Example record with special character
Example record with trailing space

@nathom
Copy link
Owner

nathom commented Jan 18, 2024

Thanks for the fix. We have a similar function implemented here

def clean_filename(fn: str, restrict: bool = False) -> str:
path = str(sanitize_filename(fn))
if restrict:
path = "".join(c for c in path if c in ALLOWED_CHARS)
return path

Can you use that instead?

@nathom nathom self-requested a review January 18, 2024 18:20
Copy link
Owner

@nathom nathom left a comment

Choose a reason for hiding this comment

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

Replace validate_str with clean_filename

@AlexKalopsia AlexKalopsia requested a review from nathom January 19, 2024 11:32
Copy link
Owner

@nathom nathom left a comment

Choose a reason for hiding this comment

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

Looks good to me

@nathom nathom merged commit 669ceee into nathom:dev Jan 19, 2024
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.

2 participants