lib/bencodr/parser.rb in bencodr-3.0.0 vs lib/bencodr/parser.rb in bencodr-3.0.1

- old
+ new

@@ -36,10 +36,14 @@ # @return [::String] the parsed string 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.encode('UTF-8') rescue byte_string.force_encoding('UTF-8') + if RUBY_VERSION =~ /1\.9/ + byte_string.encode('UTF-8') rescue byte_string.force_encoding('UTF-8') + else + byte_string + end end # This method parases a bencoded integer. # # scanner = StringScanner.new("i1e") \ No newline at end of file