Skip to content

Commit

Permalink
[Core] Discard empty strings in file paths
Browse files Browse the repository at this point in the history
Backport #518 to
the release branch.

Patch thanks to issueg2k4g34j2g
  • Loading branch information
alanmcgovern committed Mar 27, 2022
1 parent 4deac15 commit 2d5c67c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/MonoTorrent.Tests/Common/TorrentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ private BEncodedList CreateFiles ()
BEncodedList files = new BEncodedList ();

BEncodedList path = new BEncodedList {
new BEncodedString (""),
new BEncodedString (""),
new BEncodedString ("file1.txt")
};

Expand Down
12 changes: 8 additions & 4 deletions src/MonoTorrent/MonoTorrent/Torrent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,10 @@ IList<TorrentFile> LoadTorrentFiles (BEncodedList list)

case ("path.utf-8"):
foreach (BEncodedString str in ((BEncodedList) keypair.Value)) {
sb.Append (str.Text);
sb.Append (Path.DirectorySeparatorChar);
if (!BEncodedString.IsNullOrEmpty (str)) {
sb.Append (str.Text);
sb.Append (Path.DirectorySeparatorChar);
}
}
path = sb.ToString (0, sb.Length - 1);
sb.Remove (0, sb.Length);
Expand All @@ -220,8 +222,10 @@ IList<TorrentFile> LoadTorrentFiles (BEncodedList list)
case ("path"):
if (string.IsNullOrEmpty (path)) {
foreach (BEncodedString str in ((BEncodedList) keypair.Value)) {
sb.Append (str.Text);
sb.Append (Path.DirectorySeparatorChar);
if (!BEncodedString.IsNullOrEmpty (str)) {
sb.Append (str.Text);
sb.Append (Path.DirectorySeparatorChar);
}
}
path = sb.ToString (0, sb.Length - 1);
sb.Remove (0, sb.Length);
Expand Down

0 comments on commit 2d5c67c

Please sign in to comment.