Shawak / downtify

Downtify is an open source Spofity downloader which makes it possible to download all your favourite songs and/or playlists directly from spotify.
GNU General Public License v3.0
80 stars 63 forks source link

Bug with escape method line 355 of SpotifyDownloader.cs #9

Closed fordpw closed 7 years ago

fordpw commented 7 years ago

The original code threw an unhandled exception. Reason was the for example the variable filepath appended two invalid chars at the front (position 0) and the end (position string.length).

e.g. my cool song [remix edition] would end up being "my cool song [remix edition]"

We needed to determine if at position 0 or string.length and if c == ascii 34 i.e. " if at these positions then ignore otherwise it is a valid test for invalid char ;)

Also the return statement was originally Substring'ed to 100 instead of lengthOfFilename.

final code is here:

    string escape(string filepath)
    {
        //int countLettersInPathName = 0;
        //we need to write code to ignore beginning double quotes and end of string double quotes
        //either we just step over it or ignore if double quotes is position 0 and length of string
        int lengthOfFilename = filepath.Length;
        int counter = 0;
        foreach (var c in new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars()))
        {
            if (!(counter == 0 && c == 34) || !(counter == lengthOfFilename && c == 34))
            {
                filepath = filepath.Replace(c, '_');
            }
            counter++;
        }
        return filepath.Substring(0, lengthOfFilename);
    }

I am working in Visual Studio 2017 and did not see anyone else having this problem. So not sure what the deal is. It works great for me now. Thanks for all this work and effort, much appreciated !

Best

Paul

Shawak commented 7 years ago

Thank you for the report, should be fixed now.

fordpw commented 7 years ago

no problem, love the app :)

On Tue, May 16, 2017 at 8:27 PM, Maximilian notifications@github.com wrote:

Thank you for the report, this should fix the problem.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Shawak/downtify/issues/9#issuecomment-301959401, or mute the thread https://github.com/notifications/unsubscribe-auth/AD4EMM74K0iSlfWxMa6mkq8CtYSQdVAaks5r6k0XgaJpZM4NdQvF .

-- [paul w ford] e paul.w.ford@gmail.com gtalk paul.w.ford@gmail.com gPhone + 1.773.373.9497 m +1.312.953.1664 skype-to-go +1.312.235.2827 linkedin www.linkedin.com/in/paulwford w: www.paulwilliamford.net blog www.compoundthoughts.com skype paul.w.ford