Skip to content

Commit e49f606

Browse files
committed
Fix bugs related to new UTF8 properties
#47
1 parent 1c2c473 commit e49f606

File tree

4 files changed

+62
-11
lines changed

4 files changed

+62
-11
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using BencodeNET.Torrents;
3+
using FluentAssertions;
4+
using Xunit;
5+
6+
namespace BencodeNET.Tests.Torrents
7+
{
8+
public class MultiFileInfoTests
9+
{
10+
[Theory]
11+
[AutoMockedData]
12+
public void FullPath_PathIsNull_ShouldNotThrowException(MultiFileInfo multiFileInfo)
13+
{
14+
// Arrange
15+
multiFileInfo.Path = null;
16+
17+
// Act
18+
Action act = () => { var _ = multiFileInfo.FullPath; };
19+
20+
// Assert
21+
act.Should().NotThrow();
22+
multiFileInfo.FullPath.Should().BeNull();
23+
}
24+
25+
[Theory]
26+
[AutoMockedData]
27+
public void FullPathUtf8_PathUtf8IsNull_ShouldNotThrowException(MultiFileInfo multiFileInfo)
28+
{
29+
// Arrange
30+
multiFileInfo.PathUtf8 = null;
31+
32+
// Act
33+
Action act = () => { var _ = multiFileInfo.FullPathUtf8; };
34+
35+
// Assert
36+
act.Should().NotThrow();
37+
multiFileInfo.FullPathUtf8.Should().BeNull();
38+
}
39+
}
40+
}

BencodeNET/Torrents/MultiFileInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class MultiFileInfo
5151
/// </summary>
5252
public string FullPath
5353
{
54-
get => string.Join(System.IO.Path.DirectorySeparatorChar.ToString(), Path);
54+
get => Path != null ? string.Join(System.IO.Path.DirectorySeparatorChar.ToString(), Path) : null;
5555
set => Path = value.Split(new[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
5656
}
5757

@@ -60,7 +60,7 @@ public string FullPath
6060
/// </summary>
6161
public string FullPathUtf8
6262
{
63-
get => string.Join(System.IO.Path.DirectorySeparatorChar.ToString(), PathUtf8);
63+
get => PathUtf8 != null ? string.Join(System.IO.Path.DirectorySeparatorChar.ToString(), PathUtf8) : null;
6464
set => PathUtf8 = value.Split(new[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
6565
}
6666
}

BencodeNET/Torrents/TorrentParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ protected virtual MultiFileInfoList ParseMultiFileInfo(BDictionary info, Encodin
236236

237237
var list = new MultiFileInfoList
238238
{
239-
DirectoryName = info.Get<BString>(TorrentInfoFields.Name).ToString(encoding),
240-
DirectoryNameUtf8 = info.Get<BString>(TorrentInfoFields.NameUtf8).ToString(encoding)
239+
DirectoryName = info.Get<BString>(TorrentInfoFields.Name)?.ToString(encoding),
240+
DirectoryNameUtf8 = info.Get<BString>(TorrentInfoFields.NameUtf8)?.ToString(encoding)
241241
};
242242

243243
var fileInfos = info.Get<BList>(TorrentInfoFields.Files).Cast<BDictionary>()

CHANGELOG.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
...
1010

11+
## [3.1.4] - 2020-03-06
12+
### Fixed
13+
- Issue parsing torrents without both `name` and `name.utf-8` field ([#47])
14+
- Exception when accessing properties `FullPath` and `FullPathUtf8` on `MultiFileInfo` if `Path`/`PathUtf8` is null ([#47])
15+
1116
## [3.1.3] - 2020-03-03
1217
### Added
1318
- 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
1621
- New UTF-8 fields are now also added to `BDictionary` created by `Torrent.ToBDictionary` (and used by encode methods)
1722

1823
### Fixed
19-
- `Torrent.NumberOfPieces` is now correctly calculated by dividing by 20 instead of `Pieces.Length` (introduced in 3.1.0) (#48)
24+
- `Torrent.NumberOfPieces` is now correctly calculated by dividing by 20 instead of `Pieces.Length` (introduced in 3.1.0) ([#48])
2025

2126
## [3.1.0] - 2020-02-28
2227
### Added
23-
- Added `FileNameUtf8` and `PathUtf8` and `FullPathUtf8` properties to `SingleFileInfo`/`MultiFileInfo` (#47)
28+
- Added `FileNameUtf8` and `PathUtf8` and `FullPathUtf8` properties to `SingleFileInfo`/`MultiFileInfo` ([#47])
2429
- These properties reads from the `name.utf-8` and `path.utf-8` fields.
2530

2631
### Changed
27-
- `Torrent.NumberOfPieces` now uses `Pieces.Length` instead of `TotalSize` for the calculation (#48)
32+
- `Torrent.NumberOfPieces` now uses `Pieces.Length` instead of `TotalSize` for the calculation ([#48])
2833

2934
## [3.0.1] - 2019-10-17
3035
### Fixed
31-
- Fixed missing parser for `Torrent` (#44)
36+
- Fixed missing parser for `Torrent` ([#44])
3237

3338

3439
## [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
7479

7580
### Fixed
7681
- Parsing from non-seekable `Stream`s is now possible
77-
- Fixed issue parsing torrent files with non-standard 'announce-list' (#39)
82+
- Fixed issue parsing torrent files with non-standard 'announce-list' ([#39])
7883

7984

8085
## [2.3.0] - 2019-02-11
@@ -145,7 +150,8 @@ and generally better usability; albeit a bit more complex.
145150
## [1.0.0] - 2015-09-19
146151

147152

148-
[Unreleased]: ../../compare/v3.1.3...HEAD
153+
[Unreleased]: ../../compare/v3.1.4...HEAD
154+
[3.1.4]: ../../compare/v3.1.4...v3.1.4
149155
[3.1.3]: ../../compare/v3.1.0...v3.1.3
150156
[3.1.0]: ../../compare/v3.0.1...v3.1.0
151157
[3.0.1]: ../../compare/v3.0.0...v3.0.1
@@ -159,4 +165,9 @@ and generally better usability; albeit a bit more complex.
159165
[1.2.1]: ../../compare/v1.2.0...v1.2.1
160166
[1.2.0]: ../../compare/v1.1.0...v1.2.0
161167
[1.1.0]: ../../compare/v1.0.0...v1.1.0
162-
[1.0.0]: ../../releases/tag/v1.0.0
168+
[1.0.0]: ../../releases/tag/v1.0.0
169+
170+
[#48]: https://github.com/Krusen/BencodeNET/issues/48
171+
[#47]: https://github.com/Krusen/BencodeNET/issues/47
172+
[#44]: https://github.com/Krusen/BencodeNET/issues/44
173+
[#39]: https://github.com/Krusen/BencodeNET/issues/39

0 commit comments

Comments
 (0)