diff --git a/src/MonoTorrent.Tests/Common/TorrentTest.cs b/src/MonoTorrent.Tests/Common/TorrentTest.cs index 4964580f8..df94f8dbb 100644 --- a/src/MonoTorrent.Tests/Common/TorrentTest.cs +++ b/src/MonoTorrent.Tests/Common/TorrentTest.cs @@ -67,7 +67,11 @@ public void StartUp () { "created by", new BEncodedString ($"MonoTorrent/{VersionInfo.ClientVersion}") }, { "encoding", new BEncodedString ("UTF-8") }, { "info", CreateInfoDict () }, - { "private", new BEncodedString ("1") } + { "private", new BEncodedString ("1") }, + { "url-list", new BEncodedList() { + new BEncodedString ("https://example.com/8/items/"), + new BEncodedString ("/8/items/"), // this should be ignored on loading + } } }; torrent = Torrent.Load (torrentInfo); } @@ -256,6 +260,16 @@ public void Files () Assert.AreEqual (80000, torrent.Files[3].Length); } + /// + /// + /// + [Test] + public void HttpSeeds () + { + Assert.IsTrue (torrent.HttpSeeds.Count == 1); + Assert.AreEqual("https://example.com/8/items/", torrent.HttpSeeds[0]); + } + [Test] public void InvalidPath () { diff --git a/src/MonoTorrent/MonoTorrent/Torrent.cs b/src/MonoTorrent/MonoTorrent/Torrent.cs index 1ec7e7c57..18adf6acd 100644 --- a/src/MonoTorrent/MonoTorrent/Torrent.cs +++ b/src/MonoTorrent/MonoTorrent/Torrent.cs @@ -13,10 +13,10 @@ // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: -// +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -676,10 +676,14 @@ void LoadInternal (BEncodedDictionary torrentInformation, InfoHash infoHash) case ("url-list"): if (keypair.Value is BEncodedString httpSeedString) { - HttpSeeds.Add (httpSeedString.Text); + if (Uri.IsWellFormedUriString (httpSeedString.Text, UriKind.Absolute)) { + HttpSeeds.Add (httpSeedString.Text); + } } else if (keypair.Value is BEncodedList httpSeedList) { foreach (BEncodedString str in httpSeedList) - HttpSeeds.Add (str.Text); + if (Uri.IsWellFormedUriString (str.Text, UriKind.Absolute)) { + HttpSeeds.Add (str.Text); + } } break;