lib/net/ntlm/encode_util.rb in rubyntlm-0.6.0 vs lib/net/ntlm/encode_util.rb in rubyntlm-0.6.1

- old
+ new

@@ -25,11 +25,11 @@ else # Use native 1.9 string encoding functions # Decode a UTF16 string to a ASCII string # @param [String] str The string to convert def self.decode_utf16le(str) - str.force_encoding(Encoding::UTF_16LE) + str = str.dup.force_encoding(Encoding::UTF_16LE) str.encode(Encoding::UTF_8, Encoding::UTF_16LE).force_encoding('UTF-8') end # Encodes a ASCII string to a UTF16 string # @param [String] str The string to convert @@ -37,10 +37,9 @@ # encodings. This library uses string contatination to build the packet bytes. The end result is that # you can either marshal the encodings elsewhere of simply know that each time you call encode_utf16le # the function will convert the string bytes to UTF-16LE and note the encoding as UTF-8 so that byte # concatination works seamlessly. def self.encode_utf16le(str) - str = str.force_encoding('UTF-8') if [::Encoding::ASCII_8BIT,::Encoding::US_ASCII].include?(str.encoding) str.dup.force_encoding('UTF-8').encode(Encoding::UTF_16LE, Encoding::UTF_8).force_encoding('UTF-8') end end end