Skip to content

Commit

Permalink
Fix bugs related to new UTF8 properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Krusen committed Mar 6, 2020
1 parent 1c2c473 commit e49f606
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
40 changes: 40 additions & 0 deletions 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();
}
}
}
4 changes: 2 additions & 2 deletions BencodeNET/Torrents/MultiFileInfo.cs
Expand Up @@ -51,7 +51,7 @@ public class MultiFileInfo
/// </summary>
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);
}

Expand All @@ -60,7 +60,7 @@ public string FullPath
/// </summary>
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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions BencodeNET/Torrents/TorrentParser.cs
Expand Up @@ -236,8 +236,8 @@ protected virtual MultiFileInfoList ParseMultiFileInfo(BDictionary info, Encodin

var list = new MultiFileInfoList
{
DirectoryName = info.Get<BString>(TorrentInfoFields.Name).ToString(encoding),
DirectoryNameUtf8 = info.Get<BString>(TorrentInfoFields.NameUtf8).ToString(encoding)
DirectoryName = info.Get<BString>(TorrentInfoFields.Name)?.ToString(encoding),
DirectoryNameUtf8 = info.Get<BString>(TorrentInfoFields.NameUtf8)?.ToString(encoding)
};

var fileInfos = info.Get<BList>(TorrentInfoFields.Files).Cast<BDictionary>()
Expand Down
25 changes: 18 additions & 7 deletions CHANGELOG.md
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
[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

0 comments on commit e49f606

Please sign in to comment.