Ensure proper filename of generated torrent (#1085)

Ensure that the filename of a torrent file sent to browser client
doesn't contain invalid character and thus preventing HTTP Error 500.
This commit is contained in:
kmicki
2017-02-21 09:21:37 +01:00
committed by kaso17
parent 04844d6cb2
commit b8146f623f

View File

@@ -56,6 +56,12 @@ namespace Jackett.Controllers
var torrentDictionary = BEncodedDictionary.DecodeTorrent(downloadBytes); var torrentDictionary = BEncodedDictionary.DecodeTorrent(downloadBytes);
downloadBytes = torrentDictionary.Encode(); downloadBytes = torrentDictionary.Encode();
char[] invalidChars = System.IO.Path.GetInvalidFileNameChars();
for(int i=0;i<file.Count();i++)
if(invalidChars.Contains(file[i])) {
file = file.Remove(i, 1).Insert(i, " ");
}
var result = new HttpResponseMessage(HttpStatusCode.OK); var result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new ByteArrayContent(downloadBytes); result.Content = new ByteArrayContent(downloadBytes);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-bittorrent"); result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-bittorrent");