Perfect your code
With built-in code review tools, GitHub makes it easy to raise the quality bar before you ship. Join the 40 million developers who've merged over 200 million pull requests.
Sign up for free See pricing for teams and enterprisesHandle reserved characters in filepaths #1629
Conversation
This comment has been minimized.
This comment has been minimized.
welcome
bot
commented
May 16, 2019
This comment has been minimized.
This comment has been minimized.
|
Hmm, I might think that we shouldn't touch/edit the filename or path like that If I want to transfer files from Mac to Mac I would want to reserve the characters in the path/name. So it should be handled in the place where you actually read/write file(s) to/from the disc? |
This comment has been minimized.
This comment has been minimized.
|
You need to do it. All user torrent clients do it as well. Currently, webtorrent tries to write the files with the reserved characters, which fails. For example: This will actually create a 0kb |
This comment has been minimized.
This comment has been minimized.
|
For reference, BitTorrent replaces every single reserved character with an underscore. This implementation is smarter, as most of the time the change isn't even visible to the eye. |
This comment has been minimized.
This comment has been minimized.
|
I'm not saying we shouldn't do it. I just said it could be done in another way. what if a torrent had this 4 files?
( maybe could be worth to have a original and a renamed path/name ) |
This comment has been minimized.
This comment has been minimized.
|
I do see your point, but I think you have misunderstood this implementation. While most clients simply replace with an underscore, as you have written in the comment, and to no apparent issue, this one goes one step further: I have a server currently processing over 400.000 torrents and have not found a single one using any of the replacement characters. But yes, in theory it is still possible to have a duplicate, even though ridiculously unlikely. My suggestion for this case would be:
There is no way around a dynamic approach to guarantee no duplicates ever. It won't harm defining a propriety with the original path either. of course, that the user can access if they so need. |
This comment has been minimized.
This comment has been minimized.
|
@jimmywarting Found an additional issue, and for this one I don't have a good suggestion. It's very rare, but some torrent file paths go over the maximum length allowed by some operative systems (cough Windows 10 again). It results in weird undefined behavior, where the file is written but cannot be renamed, copies cannot be created under most circumstances and it cannot be found by many applications/processes (Windows explorer does though). |
This comment has been minimized.
This comment has been minimized.
|
eh, what is the maximum length allowed? |

Jaliborc commentedMay 16, 2019
These two lines of code additions show how you can easily make WebTorrent be able to handle torrents and files having paths using UNIX or POSIX reserved characters, like the majority of torrenting clients do.
It is using a tiny package I created for the purpose of replacing reserved characters with visually similar unicode characters.
See issue #1618