File tree 2 files changed +3
-4
lines changed
2 files changed +3
-4
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ def self.swap16(str)
27
27
# Decode a UTF16 string to a ASCII string
28
28
# @param [String] str The string to convert
29
29
def self . decode_utf16le ( str )
30
- str . force_encoding ( Encoding ::UTF_16LE )
30
+ str = str . dup . force_encoding ( Encoding ::UTF_16LE )
31
31
str . encode ( Encoding ::UTF_8 , Encoding ::UTF_16LE ) . force_encoding ( 'UTF-8' )
32
32
end
33
33
@@ -39,7 +39,6 @@ def self.decode_utf16le(str)
39
39
# the function will convert the string bytes to UTF-16LE and note the encoding as UTF-8 so that byte
40
40
# concatination works seamlessly.
41
41
def self . encode_utf16le ( str )
42
- str = str . force_encoding ( 'UTF-8' ) if [ ::Encoding ::ASCII_8BIT , ::Encoding ::US_ASCII ] . include? ( str . encoding )
43
42
str . dup . force_encoding ( 'UTF-8' ) . encode ( Encoding ::UTF_16LE , Encoding ::UTF_8 ) . force_encoding ( 'UTF-8' )
44
43
end
45
44
end
Original file line number Diff line number Diff line change 4
4
5
5
context '#encode_utf16le' do
6
6
it 'should convert an ASCII string to UTF' do
7
- expect ( Net ::NTLM ::EncodeUtil . encode_utf16le ( 'Test' ) ) . to eq ( "T\x00 e\x00 s\x00 t\x00 " )
7
+ expect ( Net ::NTLM ::EncodeUtil . encode_utf16le ( 'Test' . encode ( :: Encoding :: ASCII_8BIT ) . freeze ) ) . to eq ( "T\x00 e\x00 s\x00 t\x00 " )
8
8
end
9
9
end
10
10
11
11
context '#decode_utf16le' do
12
12
it 'should convert a UTF string to ASCII' do
13
- expect ( Net ::NTLM ::EncodeUtil . decode_utf16le ( "T\x00 e\x00 s\x00 t\x00 " ) ) . to eq ( 'Test' )
13
+ expect ( Net ::NTLM ::EncodeUtil . decode_utf16le ( "T\x00 e\x00 s\x00 t\x00 " . freeze ) ) . to eq ( 'Test' )
14
14
end
15
15
end
16
16
end
You can’t perform that action at this time.
0 commit comments