Skip to content

Commit f02be51

Browse files
committed
Change default TorrentParserMode to be tolerant
1 parent fcb2df0 commit f02be51

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

BencodeNET.Tests/Torrents/TorrentParserTests.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Text;
44
using BencodeNET.IO;
@@ -435,14 +435,14 @@ public void MultiFileInfo_IsParsed(string directoryName, long length1, IList<str
435435
}
436436

437437
[Fact]
438-
public void Root_MissingInfoField_ThrowsInvalidTorrentException()
438+
public void Root_MissingInfoField_Strict_ThrowsInvalidTorrentException()
439439
{
440440
// Arrange
441441
ParsedData = ValidSingleFileTorrentData;
442442
ParsedData.Remove(TorrentFields.Info);
443443

444444
// Act
445-
var parser = new TorrentParser(BencodeParser);
445+
var parser = new TorrentParser(BencodeParser, TorrentParserMode.Strict);
446446
Action action = () => parser.Parse((BencodeReader)null);
447447

448448
// Assert
@@ -451,7 +451,7 @@ public void Root_MissingInfoField_ThrowsInvalidTorrentException()
451451
}
452452

453453
[Fact]
454-
public void Info_ContainingBothLengthAndFilesField_ThrowsInvalidTorrentException()
454+
public void Info_ContainingBothLengthAndFilesField_Strict_ThrowsInvalidTorrentException()
455455
{
456456
// Arrange
457457
ParsedData = ValidSingleFileTorrentData;
@@ -460,7 +460,7 @@ public void Info_ContainingBothLengthAndFilesField_ThrowsInvalidTorrentException
460460
info[TorrentInfoFields.Files] = new BList();
461461

462462
// Act
463-
var parser = new TorrentParser(BencodeParser);
463+
var parser = new TorrentParser(BencodeParser, TorrentParserMode.Strict);
464464
Action action = () => parser.Parse((BencodeReader)null);
465465

466466
// Assert
@@ -470,15 +470,15 @@ public void Info_ContainingBothLengthAndFilesField_ThrowsInvalidTorrentException
470470
}
471471

472472
[Fact]
473-
public void Info_MissingPieceLengthField_ThrowsInvalidTorrentException()
473+
public void Info_MissingPieceLengthField_Strict_ThrowsInvalidTorrentException()
474474
{
475475
// Arrange
476476
ParsedData = ValidSingleFileTorrentData;
477477
var info = ParsedData.Get<BDictionary>(TorrentFields.Info);
478478
info.Remove(TorrentInfoFields.PieceLength);
479479

480480
// Act
481-
var parser = new TorrentParser(BencodeParser);
481+
var parser = new TorrentParser(BencodeParser, TorrentParserMode.Strict);
482482
Action action = () => parser.Parse((BencodeReader)null);
483483

484484
// Assert
@@ -487,15 +487,15 @@ public void Info_MissingPieceLengthField_ThrowsInvalidTorrentException()
487487
}
488488

489489
[Fact]
490-
public void Info_MissingPiecesField_ThrowsInvalidTorrentException()
490+
public void Info_MissingPiecesField_Strict_ThrowsInvalidTorrentException()
491491
{
492492
// Arrange
493493
ParsedData = ValidSingleFileTorrentData;
494494
var info = ParsedData.Get<BDictionary>(TorrentFields.Info);
495495
info.Remove(TorrentInfoFields.Pieces);
496496

497497
// Act
498-
var parser = new TorrentParser(BencodeParser);
498+
var parser = new TorrentParser(BencodeParser, TorrentParserMode.Strict);
499499
Action action = () => parser.Parse((BencodeReader)null);
500500

501501
// Assert
@@ -504,15 +504,15 @@ public void Info_MissingPiecesField_ThrowsInvalidTorrentException()
504504
}
505505

506506
[Fact]
507-
public void Info_MissingNameField_ThrowsInvalidTorrentException()
507+
public void Info_MissingNameField_Strict_ThrowsInvalidTorrentException()
508508
{
509509
// Arrange
510510
ParsedData = ValidSingleFileTorrentData;
511511
var info = ParsedData.Get<BDictionary>(TorrentFields.Info);
512512
info.Remove(TorrentInfoFields.Name);
513513

514514
// Act
515-
var parser = new TorrentParser(BencodeParser);
515+
var parser = new TorrentParser(BencodeParser, TorrentParserMode.Strict);
516516
Action action = () => parser.Parse((BencodeReader)null);
517517

518518
// Assert
@@ -521,15 +521,15 @@ public void Info_MissingNameField_ThrowsInvalidTorrentException()
521521
}
522522

523523
[Fact]
524-
public void MultiFileInfo_MissingFilesField_ThrowsInvalidTorrentException()
524+
public void MultiFileInfo_MissingFilesField_Strict_ThrowsInvalidTorrentException()
525525
{
526526
// Arrange
527527
ParsedData = ValidMultiFileTorrentData;
528528
var info = ParsedData.Get<BDictionary>(TorrentFields.Info);
529529
info.Remove(TorrentInfoFields.Files);
530530

531531
// Act
532-
var parser = new TorrentParser(BencodeParser);
532+
var parser = new TorrentParser(BencodeParser, TorrentParserMode.Strict);
533533
Action action = () => parser.Parse((BencodeReader)null);
534534

535535
// Assert
@@ -538,7 +538,7 @@ public void MultiFileInfo_MissingFilesField_ThrowsInvalidTorrentException()
538538
}
539539

540540
[Fact]
541-
public void MultiFile_Files_MissingLengthField_ThrowsInvalidTorrentException()
541+
public void MultiFile_Files_MissingLengthField_Strict_ThrowsInvalidTorrentException()
542542
{
543543
// Arrange
544544
ParsedData = ValidMultiFileTorrentData;
@@ -552,7 +552,7 @@ public void MultiFile_Files_MissingLengthField_ThrowsInvalidTorrentException()
552552
};
553553

554554
// Act
555-
var parser = new TorrentParser(BencodeParser);
555+
var parser = new TorrentParser(BencodeParser, TorrentParserMode.Strict);
556556
Action action = () => parser.Parse((BencodeReader)null);
557557

558558
// Assert
@@ -561,7 +561,7 @@ public void MultiFile_Files_MissingLengthField_ThrowsInvalidTorrentException()
561561
}
562562

563563
[Fact]
564-
public void MultiFile_Files_MissingPathField_ThrowsInvalidTorrentException()
564+
public void MultiFile_Files_MissingPathField_Strict_ThrowsInvalidTorrentException()
565565
{
566566
// Arrange
567567
ParsedData = ValidMultiFileTorrentData;
@@ -575,7 +575,7 @@ public void MultiFile_Files_MissingPathField_ThrowsInvalidTorrentException()
575575
};
576576

577577
// Act
578-
var parser = new TorrentParser(BencodeParser);
578+
var parser = new TorrentParser(BencodeParser, TorrentParserMode.Strict);
579579
Action action = () => parser.Parse((BencodeReader)null);
580580

581581
// Assert

BencodeNET/Torrents/TorrentParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public TorrentParser(TorrentParserMode torrentParserMode)
4545
/// </summary>
4646
/// <param name="bencodeParser">The parser used for parsing the torrent <see cref="BDictionary"/>.</param>
4747
public TorrentParser(IBencodeParser bencodeParser)
48-
: this(bencodeParser, TorrentParserMode.Strict)
48+
: this(bencodeParser, TorrentParserMode.Tolerant)
4949
{
5050
}
5151

0 commit comments

Comments
 (0)