Skip to content

Commit da2bf20

Browse files
mindless2112Krusen
authored andcommitted
Fix wrong error message when parsing unterminated list or number (#32)
1 parent b9b5777 commit da2bf20

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

BencodeNET/Parsing/BListParser.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ public override BList Parse(BencodeStream stream)
6464
}
6565

6666
if (stream.ReadChar() != 'e')
67+
{
68+
if (stream.EndOfStream) throw InvalidBencodeException<BList>.MissingEndChar();
6769
throw InvalidBencodeException<BList>.InvalidEndChar(stream.ReadPreviousChar(), stream.Position);
70+
}
6871

6972
return list;
7073
}

BencodeNET/Parsing/BNumberParser.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ public override BNumber Parse(BencodeStream stream)
5151

5252
// Last read character should be 'e'
5353
if (c != 'e')
54+
{
55+
if (stream.EndOfStream) throw InvalidBencodeException<BNumber>.MissingEndChar();
5456
throw InvalidBencodeException<BNumber>.InvalidEndChar(c, stream.Position);
57+
}
5558

5659
var isNegative = digits[0] == '-';
5760
var numberOfDigits = isNegative ? digits.Length - 1 : digits.Length;

0 commit comments

Comments
 (0)