diff --git a/BencodeNET.Tests/Torrents/MultiFileInfoTests.cs b/BencodeNET.Tests/Torrents/MultiFileInfoTests.cs new file mode 100644 index 0000000000..77b8720b88 --- /dev/null +++ b/BencodeNET.Tests/Torrents/MultiFileInfoTests.cs @@ -0,0 +1,40 @@ +using System; +using BencodeNET.Torrents; +using FluentAssertions; +using Xunit; + +namespace BencodeNET.Tests.Torrents +{ + public class MultiFileInfoTests + { + [Theory] + [AutoMockedData] + public void FullPath_PathIsNull_ShouldNotThrowException(MultiFileInfo multiFileInfo) + { + // Arrange + multiFileInfo.Path = null; + + // Act + Action act = () => { var _ = multiFileInfo.FullPath; }; + + // Assert + act.Should().NotThrow(); + multiFileInfo.FullPath.Should().BeNull(); + } + + [Theory] + [AutoMockedData] + public void FullPathUtf8_PathUtf8IsNull_ShouldNotThrowException(MultiFileInfo multiFileInfo) + { + // Arrange + multiFileInfo.PathUtf8 = null; + + // Act + Action act = () => { var _ = multiFileInfo.FullPathUtf8; }; + + // Assert + act.Should().NotThrow(); + multiFileInfo.FullPathUtf8.Should().BeNull(); + } + } +} diff --git a/BencodeNET/Torrents/MultiFileInfo.cs b/BencodeNET/Torrents/MultiFileInfo.cs index bf3a85244d..403d2a8dff 100644 --- a/BencodeNET/Torrents/MultiFileInfo.cs +++ b/BencodeNET/Torrents/MultiFileInfo.cs @@ -51,7 +51,7 @@ public class MultiFileInfo /// public string FullPath { - get => string.Join(System.IO.Path.DirectorySeparatorChar.ToString(), Path); + get => Path != null ? string.Join(System.IO.Path.DirectorySeparatorChar.ToString(), Path) : null; set => Path = value.Split(new[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries); } @@ -60,7 +60,7 @@ public string FullPath /// public string FullPathUtf8 { - get => string.Join(System.IO.Path.DirectorySeparatorChar.ToString(), PathUtf8); + get => PathUtf8 != null ? string.Join(System.IO.Path.DirectorySeparatorChar.ToString(), PathUtf8) : null; set => PathUtf8 = value.Split(new[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries); } } diff --git a/BencodeNET/Torrents/TorrentParser.cs b/BencodeNET/Torrents/TorrentParser.cs index 00b618f7b9..2fde44558c 100644 --- a/BencodeNET/Torrents/TorrentParser.cs +++ b/BencodeNET/Torrents/TorrentParser.cs @@ -236,8 +236,8 @@ protected virtual MultiFileInfoList ParseMultiFileInfo(BDictionary info, Encodin var list = new MultiFileInfoList { - DirectoryName = info.Get(TorrentInfoFields.Name).ToString(encoding), - DirectoryNameUtf8 = info.Get(TorrentInfoFields.NameUtf8).ToString(encoding) + DirectoryName = info.Get(TorrentInfoFields.Name)?.ToString(encoding), + DirectoryNameUtf8 = info.Get(TorrentInfoFields.NameUtf8)?.ToString(encoding) }; var fileInfos = info.Get(TorrentInfoFields.Files).Cast() diff --git a/CHANGELOG.md b/CHANGELOG.md index 71d8d12053..990fd26215 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ... +## [3.1.4] - 2020-03-06 +### Fixed +- Issue parsing torrents without both `name` and `name.utf-8` field ([#47]) +- Exception when accessing properties `FullPath` and `FullPathUtf8` on `MultiFileInfo` if `Path`/`PathUtf8` is null ([#47]) + ## [3.1.3] - 2020-03-03 ### Added - Added `Torrent.DisplayNameUtf8` and `MultiFileInfoList.DirectoryNameUtf8`, both mapped to the `name.utf-8` field @@ -16,19 +21,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - New UTF-8 fields are now also added to `BDictionary` created by `Torrent.ToBDictionary` (and used by encode methods) ### Fixed -- `Torrent.NumberOfPieces` is now correctly calculated by dividing by 20 instead of `Pieces.Length` (introduced in 3.1.0) (#48) +- `Torrent.NumberOfPieces` is now correctly calculated by dividing by 20 instead of `Pieces.Length` (introduced in 3.1.0) ([#48]) ## [3.1.0] - 2020-02-28 ### Added -- Added `FileNameUtf8` and `PathUtf8` and `FullPathUtf8` properties to `SingleFileInfo`/`MultiFileInfo` (#47) +- Added `FileNameUtf8` and `PathUtf8` and `FullPathUtf8` properties to `SingleFileInfo`/`MultiFileInfo` ([#47]) - These properties reads from the `name.utf-8` and `path.utf-8` fields. ### Changed -- `Torrent.NumberOfPieces` now uses `Pieces.Length` instead of `TotalSize` for the calculation (#48) +- `Torrent.NumberOfPieces` now uses `Pieces.Length` instead of `TotalSize` for the calculation ([#48]) ## [3.0.1] - 2019-10-17 ### Fixed -- Fixed missing parser for `Torrent` (#44) +- Fixed missing parser for `Torrent` ([#44]) ## [3.0.0] - 2019-10-13 @@ -74,7 +79,7 @@ Lowest supported versions are now .NET Framework 4.6.1 (4.7.2 highly recommended ### Fixed - Parsing from non-seekable `Stream`s is now possible -- Fixed issue parsing torrent files with non-standard 'announce-list' (#39) +- Fixed issue parsing torrent files with non-standard 'announce-list' ([#39]) ## [2.3.0] - 2019-02-11 @@ -145,7 +150,8 @@ and generally better usability; albeit a bit more complex. ## [1.0.0] - 2015-09-19 -[Unreleased]: ../../compare/v3.1.3...HEAD +[Unreleased]: ../../compare/v3.1.4...HEAD +[3.1.4]: ../../compare/v3.1.4...v3.1.4 [3.1.3]: ../../compare/v3.1.0...v3.1.3 [3.1.0]: ../../compare/v3.0.1...v3.1.0 [3.0.1]: ../../compare/v3.0.0...v3.0.1 @@ -159,4 +165,9 @@ and generally better usability; albeit a bit more complex. [1.2.1]: ../../compare/v1.2.0...v1.2.1 [1.2.0]: ../../compare/v1.1.0...v1.2.0 [1.1.0]: ../../compare/v1.0.0...v1.1.0 -[1.0.0]: ../../releases/tag/v1.0.0 \ No newline at end of file +[1.0.0]: ../../releases/tag/v1.0.0 + +[#48]: https://github.com/Krusen/BencodeNET/issues/48 +[#47]: https://github.com/Krusen/BencodeNET/issues/47 +[#44]: https://github.com/Krusen/BencodeNET/issues/44 +[#39]: https://github.com/Krusen/BencodeNET/issues/39 \ No newline at end of file