zerratar / SubSync

Automatically download subtitles for your movies
MIT License
290 stars 26 forks source link

Trailing \ on UNC paths crashes #12

Closed hellfirehd closed 6 years ago

hellfirehd commented 6 years ago

Launching with:

PS D:\SubSync\> dotnet run --project .\src\SubSync\SubSync.csproj '\\C3P0\Storage\media\TV\Bull (2016)\'
...
   Following folder and its subfolders being watched
     \\C3P0\Storage\media\TV\Bull (2016)"
...
Unhandled Exception: System.ArgumentException: The directory name \\C3P0\Storage\media\TV\Bull (2016)" is invalid.
Parameter name: path
   at System.IO.FileSystemWatcher..ctor(String path, String filter)
   at SubSyncLib.Logic.SubtitleSynchronizer.Start() in D:\Source\3rdParty\SubSync\src\SubSyncLib\Logic\SubtitleSynchronizer.cs:line 53
   at SubSyncLib.Program.Main(String[] args) in D:\Source\3rdParty\SubSync\src\SubSyncLib\Program.cs:line 66
   at SubSync.Program.Main(String[] args) in D:\Source\3rdParty\SubSync\src\SubSync\Program.cs:line 10

The same path without the trailing \ runs fine.

hellfirehd commented 6 years ago

It might have something to do with having a space in the path as the following path with a trailing \ works:

PS D:\SubSync> dotnet run --project .\src\SubSync\SubSync.csproj '\\C3P0\Storage\media\Movies\'
zerratar commented 6 years ago

Hmm, strange! Almost sounds like a bug in the FileSystemWatcher itself. Just to be sure I got it right.

these works: dotnet run --project .\src\SubSync\SubSync.csproj '\\C3P0\Storage\media\TV\Bull (2016)' dotnet run --project .\src\SubSync\SubSync.csproj '\\C3P0\Storage\media\Movies\'

this does not work: dotnet run --project .\src\SubSync\SubSync.csproj '\\C3P0\Storage\media\TV\Bull (2016)\'

?

I will play around with it and see if i can recreate the error. If not, I will just trim all trailing backslashes from the paths.

Thanks for reporting this, @hellfirehd! 👍

zerratar commented 6 years ago

Ok. This is crazy.

This is actually a bug in the dotnet core! When it reads the argument that is passed in using double or single quoutes AND when having a trailing backslash it will actually include the single/double quoute as part of the text.

when you pass: '\\C3P0\Storage\media\TV\Bull (2016)' it is read as: \\C3P0\Storage\media\TV\Bull (2016) without quotes. when you pass: '\\C3P0\Storage\media\TV\Bull (2016)\' it is read as: \\C3P0\Storage\media\TV\Bull (2016)\'

Luckily its very specific. It will either include a backslash and single or double quote. which makes it rather easy to make a workaround for.