rspec-support 3.2.1 → 3.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Changelog.md +7 -0
- data/lib/rspec/support/encoded_string.rb +50 -24
- data/lib/rspec/support/version.rb +1 -1
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60a2be459dac1db7bb1f0e0744c43f44096ba5f1
|
4
|
+
data.tar.gz: d0aa42011432477ee8022bba5dd6ab339639e1f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b68e8f0bc090208f255295646f95c41bbb925fe7068615ab82058bbfa0101895d4b94ae3f4482fa1270dc7e9532b053cc9c735918955e1cf46fe4664b0dd3043
|
7
|
+
data.tar.gz: 96062033ec6dfc37bd8d3e430353839c55f04dbaf3f6385b69190e8bee61d821ad966809904f499ff5bc7c7685f4d7d478b8b02f09ec405a22a45cae3e2b3659
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/Changelog.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
### 3.2.2 / 2015-02-23
|
2
|
+
|
3
|
+
Bug Fixes:
|
4
|
+
|
5
|
+
* Fix an encoding issue with `EncodedString#split` when encountering an
|
6
|
+
invalid byte string. (Benjamin Fleischer, #1760)
|
7
|
+
|
1
8
|
### 3.2.1 / 2015-02-04
|
2
9
|
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.2.0...v3.2.1)
|
3
10
|
|
@@ -3,16 +3,32 @@ module RSpec
|
|
3
3
|
# @private
|
4
4
|
class EncodedString
|
5
5
|
# Reduce allocations by storing constants.
|
6
|
-
UTF_8
|
7
|
-
US_ASCII =
|
8
|
-
#
|
6
|
+
UTF_8 = "UTF-8"
|
7
|
+
US_ASCII = "US-ASCII"
|
8
|
+
#
|
9
|
+
# In MRI 2.1 'invalid: :replace' changed to also replace an invalid byte sequence
|
10
|
+
# see https://github.com/ruby/ruby/blob/v2_1_0/NEWS#L176
|
11
|
+
# https://www.ruby-forum.com/topic/6861247
|
12
|
+
# https://twitter.com/nalsh/status/553413844685438976
|
13
|
+
#
|
14
|
+
# For example, given:
|
15
|
+
# "\x80".force_encoding("Emacs-Mule").encode(:invalid => :replace).bytes.to_a
|
16
|
+
#
|
17
|
+
# On MRI 2.1 or above: 63 # '?'
|
18
|
+
# else : 128 # "\x80"
|
19
|
+
#
|
20
|
+
# Ruby's default replacement string is:
|
21
|
+
# U+FFFD ("\xEF\xBF\xBD"), for Unicode encoding forms, else
|
22
|
+
# ? ("\x3F")
|
9
23
|
REPLACE = "?"
|
10
24
|
ENCODE_UNCONVERTABLE_BYTES = {
|
11
25
|
:invalid => :replace,
|
12
|
-
:undef => :replace
|
26
|
+
:undef => :replace,
|
27
|
+
:replace => REPLACE
|
13
28
|
}
|
14
29
|
ENCODE_NO_CONVERTER = {
|
15
30
|
:invalid => :replace,
|
31
|
+
:replace => REPLACE
|
16
32
|
}
|
17
33
|
|
18
34
|
def initialize(string, encoding=nil)
|
@@ -54,7 +70,7 @@ module RSpec
|
|
54
70
|
# vs "\x80".encode('UTF-8','ASCII-8BIT', undef: :replace, replace: '<undef>')
|
55
71
|
# # => '<undef>'
|
56
72
|
# Encoding::CompatibilityError
|
57
|
-
#
|
73
|
+
# when Encoding.compatibile?(str1, str2) is nil
|
58
74
|
# e.g. utf_16le_emoji_string.split("\n")
|
59
75
|
# e.g. valid_unicode_string.encode(utf8_encoding) << ascii_string
|
60
76
|
# Encoding::InvalidByteSequenceError:
|
@@ -64,13 +80,13 @@ module RSpec
|
|
64
80
|
# vs "\x80".encode('UTF-8','US-ASCII', invalid: :replace, replace: '<byte>')
|
65
81
|
# # => '<byte>'
|
66
82
|
# ArgumentError
|
67
|
-
#
|
68
|
-
# e.g."\
|
83
|
+
# when operating on a string with invalid bytes
|
84
|
+
# e.g."\x80".split("\n")
|
69
85
|
# TypeError
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
86
|
+
# when a symbol is passed as an encoding
|
87
|
+
# Encoding.find(:"UTF-8")
|
88
|
+
# when calling force_encoding on an object
|
89
|
+
# that doesn't respond to #to_str
|
74
90
|
#
|
75
91
|
# Raised by transcoding methods:
|
76
92
|
# Encoding::ConverterNotFoundError:
|
@@ -80,25 +96,35 @@ module RSpec
|
|
80
96
|
# e.g. "\x80".force_encoding('ASCII-8BIT').encode('Emacs-Mule')
|
81
97
|
#
|
82
98
|
# Raised by byte <-> char conversions
|
83
|
-
#
|
84
|
-
#
|
99
|
+
# RangeError: out of char range
|
100
|
+
# e.g. the UTF-16LE emoji: 128169.chr
|
85
101
|
def matching_encoding(string)
|
102
|
+
string = remove_invalid_bytes(string)
|
86
103
|
string.encode(@encoding)
|
87
104
|
rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError
|
88
|
-
|
105
|
+
string.encode(@encoding, ENCODE_UNCONVERTABLE_BYTES)
|
89
106
|
rescue Encoding::ConverterNotFoundError
|
90
|
-
|
107
|
+
string.dup.force_encoding(@encoding).encode(ENCODE_NO_CONVERTER)
|
91
108
|
end
|
92
109
|
|
93
|
-
#
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
110
|
+
# Prevents raising ArgumentError
|
111
|
+
if String.method_defined?(:scrub)
|
112
|
+
# https://github.com/ruby/ruby/blob/eeb05e8c11/doc/NEWS-2.1.0#L120-L123
|
113
|
+
# https://github.com/ruby/ruby/blob/v2_1_0/string.c#L8242
|
114
|
+
# https://github.com/hsbt/string-scrub
|
115
|
+
# https://github.com/rubinius/rubinius/blob/v2.5.2/kernel/common/string.rb#L1913-L1972
|
116
|
+
def remove_invalid_bytes(string)
|
117
|
+
string.scrub(REPLACE)
|
118
|
+
end
|
119
|
+
else
|
120
|
+
# http://stackoverflow.com/a/8711118/879854
|
121
|
+
# Loop over chars in a string replacing chars
|
122
|
+
# with invalid encoding, which is a pretty good proxy
|
123
|
+
# for the invalid byte sequence that causes an ArgumentError
|
124
|
+
def remove_invalid_bytes(string)
|
125
|
+
string.chars.map do |char|
|
126
|
+
char.valid_encoding? ? char : REPLACE
|
127
|
+
end.join
|
102
128
|
end
|
103
129
|
end
|
104
130
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.2.
|
4
|
+
version: 3.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Chelimsky
|
@@ -48,7 +48,7 @@ cert_chain:
|
|
48
48
|
ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
|
49
49
|
F3MdtaDehhjC
|
50
50
|
-----END CERTIFICATE-----
|
51
|
-
date: 2015-02-
|
51
|
+
date: 2015-02-24 00:00:00.000000000 Z
|
52
52
|
dependencies:
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: bundler
|
@@ -134,5 +134,5 @@ rubyforge_project: rspec
|
|
134
134
|
rubygems_version: 2.2.2
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
|
-
summary: rspec-support-3.2.
|
137
|
+
summary: rspec-support-3.2.2
|
138
138
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|