Skip to content
This repository has been archived by the owner on Dec 24, 2023. It is now read-only.

Commit

Permalink
Update lib/bencodr/parser.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarangp committed May 30, 2012
1 parent 4e48e7b commit 92f6284
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/bencodr/parser.rb
Expand Up @@ -37,7 +37,8 @@ def parse_object(scanner)
def parse_string(scanner)
length = scanner.scan(/[1-9][0-9]*|0/) or raise BEncodeError, "Invalid string: length invalid. #{scanner.pos}"
scanner.scan(/:/) or raise BEncodeError, "Invalid string: missing colon(:). #{scanner.pos}"
byte_string = scanner.scan(/.{#{length}}/m) or raise BEncodeError, "Invalid string: length too long(#{length}) #{scanner.pos}."
byte_string= scanner.peek(length.to_i) or raise BEncodeError, "Invalid string: length too long(#{length}) #{scanner.pos}."
scanner.pos = scanner.pos + length.to_i or raise BEncodeError, "Invalid string: length too long(#{length}) #{scanner.pos}."
if RUBY_VERSION =~ /1\.9/
byte_string.encode('UTF-8') rescue byte_string.force_encoding('UTF-8')
else
Expand Down

0 comments on commit 92f6284

Please sign in to comment.